Implementation of Disconf. Net,

Source: Internet
Author: User

Implementation of Disconf. Net,

Source Code address: https://github.com/qkbao/Disconf.Net

Author: starfd contact qq: 407658487

 

To better solve the problem of unified Configuration Management for multiple service instances in a distributed environment, this paper proposes a complete distributed configuration management solution. Based on the specific circumstances of the. net project, the configuration publishing is unified, the configuration is managed persistently, And the restful interface is provided externally. On this basis, the configuration change is pushed in real time based on ZooKeeper. The system has implemented and improved some functions by referring to Baidu's Disconf, which is the. Net Lite version of Disconf. The functions need to be further improved.

1. System Design 1.1 Design Philosophy

L ease of use and good user experience

L support Distributed Management of configuration (KV configuration items + configuration files)

L unified configuration publishing and updating: users can publish and update configurations on the platform.

L automatic configuration update: the user updates the configuration on the platform. The system that uses the configuration will automatically detect this situation and apply the new configuration.

 

The system structure is as follows:

 

 

During initialization, the business flow chart is as follows:

 

During configuration update, the business flow chart is as follows:

 

1. 2. Features

The system module architecture is as follows:

 

1.2.1Client

Configuration Management Module: centrally manages local configuration files and configuration items in user instances

Download module: restful download configuration files and configuration items

Watch module: monitors changes in remote configuration files and configuration items

1.2.2Web

Configuration Management Module: supports uploading, downloading, and updating configuration templates (configuration items or configuration files ).

Configuration storage module: manages the storage and reading of all configurations. project configuration is distinguished based on appName, version, and environment.

Notification module: After the configuration is updated, all instances with these configurations are notified in real time.

Permission control: Permission Control for web users

2. Add the clientConfig configuration node in client application 2.1

Add the configuration under the configSections node in app. config or web. config.

<Section name = "clientConfig" type = "Disconf. Net. Client. ClientConfigSection, Disconf. Net. Client"/>

Then add the clientConfig configuration on the nodes at the same level as the deleteconfig. The example is as follows:

<ConfigSections>

<Section name = "clientConfig" type = "Disconf. Net. Client. ClientConfigSection, Disconf. Net. Client"/>

</ConfigSections>

<Etetaskfile = "appsetask. config"/>

<ClientConfig configSource = "clientConfig. config"/>

2.2clientConfig

Example:

<ClientConfigWebApiHost= "Http: // 192.168.1.100: 8088 /"EnableRemote= "True">

<ClientInfoAppName= "Leletest"Environment= "Dev"Version= "1.0.0.0"ClientName= "Lele_1"/>

<UpdateStrategyFileIgnores= "Notdown.txt"ItemIgnores= "Aa, bb, cc"StartedSync= "True"RetryTimes= "3"RetryIntervalSeconds= "10"/>

<PreservationAbsolutePath= "False"TmpRootDirectory= "Tmp \ Download \ Configs"FactRootDirectory= ""TmpItemsLocalName= "~ Items. xml "tmpFilesLocalName = "~ Files.txt "/>

</ClientConfig>

 

Node name

Required

Default Value

Node description

WebApiHost

 

Y

 

Rest server domain name address

EnableRemote

 

N

True

Whether to enable remote configuration. The default value is true. If it is set to false, the configuration is not downloaded from the remote server.

ClientInfo

AppName

Y

 

Client program name. Make sure that the case is the same as that of the server.

Environment

Y

 

The environment where the current client program is located. Note that the case sensitivity must be consistent with that on the server.

Version

Y

 

The current client version. Note that the case sensitivity must be the same as that of the server.

ClientName

N

 

Client ID, used by the server to view updated clients. If not set, the client computer name is obtained by default.

UpdateStrategy

FileIgnores

N

 

The updated file configuration should be ignored and separated. Note that the case sensitivity must be consistent with that on the server.

ItemIgnores

N

 

The updated key-Value Pair configuration should be ignored and separated. Note that the case sensitivity must be consistent with that on the server.

StartedSync

N

True

Whether to load data synchronously at startup. synchronization is performed by default.

RetryTimes

N

3

Number of Retries when the query fails

RetryIntervalSeconds

N

10

Interval of each retry, in seconds

Preservation

AbsolutePath

N

False

Whether the path is absolute. The default value is false. If false, the default value is

AppDomain. CurrentDomain. BaseDirectory is a comparison point. Note: This configuration applies to both TmpRootDirectory and,

FactRootDirectory: either absolute or relative paths are allowed.

TmpRootDirectory

N

Tmp/Download/Configs

The downloaded configuration temporarily saves the root directory of the folder.

FactRootDirectory

N

Configs

The actual root directory of the configuration file

TmpItemsLocalName

N

~ Items. xml

The file name used to save all key-value pairs in the temporary directory. If it is set to null, the file is not saved. The file is saved in the TmpRootDirectory directory.

Actual Configuration File Name Conflict

 

TmpFilesLocalName

N

~ Files.txt

The file name used to save the configuration names of all files in the temporary directory. If it is set to null, the file is not saved. The file is saved in the TmpRootDirectory directory. Therefore, do not conflict with the actual configuration file name.

 

2.3 Rules

In addition to configuration, you also need to set an update policy before the client can perform Configuration updates. Currently, the Rules setting only supports encoding. There are two types of Rule: FileRule and ItemRule, which are described below:

FileRule: Used to set how to update the file type configuration. It includes the following methods:

Method Name

Description

IFileRule MapTo (string refreshSectionName)

Register the Rule and set the default file configuration ing.

The refreshSectionName parameter indicates that when the callback is updated,

The node name to be refreshed in ConfigurationManager. RefreshSection. The configName configured remotely is used by default.

IFileRule RefreshIgnores ()

The ConfigurationManager. RefreshSection method is not automatically called to update the configuration.

IFileRule CallBack (Action action)

After the file is downloaded and replaced with the local file, callback is triggered. Note that the delegated link is used, that is, multiple calls are executed.

ItemRule: Used to set how to update the key-Value Pair type configuration. It includes the following methods:

Method Name

Description

IItemRule MapTo (string propName)

Register Rule rules and set default property ing parameters

PropName indicates the attribute name to be assigned a value. The remote configName is used by default.

IItemRule SetProperty <T> (T entity, string propName = null, Func <string, object> typeConvert = null)

Update the attribute value of a specified object and obtain the instance attributes by default. Note that multiple calls will be executed.

IItemRule SetProperty (object entity, PropertyInfo prop, Func <string, object> typeConvert = null)

Update the attribute value of a specified object. Note that multiple calls will be executed.

IItemRule SetStaticProperty <T> (string propName = null, Func <string, object> typeConvert = null)

Update the static property value and obtain the static property by default. Note that multiple calls will be executed.

IItemRule SetStaticProperty (PropertyInfo prop, Func <string, object> typeConvert = null)

Update the value of the static attribute. Note that multiple calls will be executed here.

IItemRule CallBack (Action <string> action)

How to perform callback when the value changes? Note that the delegated link is used here, that is, multiple calls will be executed.

2.4 ConfigManager

This class is the Client configuration entry. It provides a unique instance through Singleton. In addition to providing the Rules configuration entry, it also provides exception notification events.

To make Disconf. net. the specified method manager must be executed. init (), and before init, you also need to set Rule and Fault. You can use ConfigManager. instance to obtain the Instance object of this class, and then set the related Rule through the corresponding Rule, the example is as follows:

// File to be updated

ConfigManager. Instance. FileRules. For ("maid. config"). CallBack () => {

Console. WriteLine ("File changed notice twice ");

});

// Key-value pair to be updated

ConfigManager. Instance. ItemRules. For ("Dai"). MapTo ("Person"). SetStaticProperty <Program> (). CallBack (v => {

Console. WriteLine ("Now item value: {0}", v );

Console. WriteLine ("Program. Person is {0} now", Program. Person );

If (v. Length> 3)

{

Throw new Exception ("Too Long ");

}

});

// Ignore the updated local key-Value Pair

ConfigManager. Instance. ItemRules. For ("Peng"). CallBack (v => {

Console. WriteLine ("Now item value: {0}", v );

});

// Exception Handling

ConfigManager. Instance. Faulted + = Manager_Faulted;

// Config initialization, including ZooKeeper and scan

ConfigManager. Instance. Init ();

Note:

1. File is used to overwrite the File at the specified location after downloading. Therefore, you can set the default Rule for the Rule, as shown in the example of resumettings. config, which corresponds to the deleteworkflow part in the config file. If you do not need to call CallBack and the file name (remove the suffix) part is consistent with the Section, you can ignore this part of the Rule settings, the program automatically performs default settings during initialization. For items, because the update policy cannot be confirmed, if the Rule is not set, the value is obtained from the server, this part can only be ignored.

2. For the Exception part, the program simply transmits the Exception information through the Faulted event. This event has only one Exception type parameter.

3. web Applications

Configuration steps:

1. Create a specific application (Project)

2. Create an application configuration template (1 ~ N CONFIGURATION templates, such as deleetting. config, redisconfig. config, and rabbitMQConfig. config)

3. Create an application environment (such as the development environment, test environment, and simulation environment) and modify related configurations.

4. Enable the corresponding configuration

5. Now, the client can obtain all the configurations of the application environment.

3.1 Login

Log on to the configuration management page.

3.2 applications

 

[New]: Enter the application name. The application description is saved and created. Return to the Application Management Homepage.

[Initialize ZooKeeper]: Zookeeper initialization at the first startup.

[Edit]: consistent with the new interface, you can modify the application name and application description. Save it and return to the Application Management Homepage.

[Edit Environment]: Go to the Environment Configuration Management Homepage.

[Delete]: Delete the corresponding application record.

3.3 Template

All templates are displayed. before configuring the operation environment, you must configure the template to perform operations on the configuration of the corresponding environment according to the template.

 

[New]: adds a template, and fills in the template name, description, type, default version number, and so on, such as selecting a file type. You can upload a file to read the file content. You can select an existing version number or create a new version number.

[Edit]: The operation is the same as creating a template. You can modify the template content.

[Delete]: click "delete" to delete the corresponding template record. If the template contains a configuration item in the environment, the template cannot be deleted. You need to delete the configuration item for the template, to delete the template.

3.4 Environment

[Add Environment] Click the plus sign to add an environment, enter the environment name, and save the description.

 

Edit Environment: Right-click the corresponding environment to bring up the Edit menu. Click Edit to Edit the environment and modify the name and content.

 

[Configuration homepage]: The configuration homepage is classified by version. The first version of the header is displayed by default. You can click another version to switch. The displayed configuration item is the default configuration item of the template. Click "enable" to assign a personalized value, assign values to different environments. Edit and edit the corresponding configuration. Disabling is equivalent to deleting the configuration.

 

[Enable configuration]: The default name cannot be modified. You can click to use the default value to directly assign values. You can also upload files and use the file content to save them.

[Edit configuration]: The operation is the same as enabling configuration. You can modify the value after saving the configuration.

Disable configuration: It is equivalent to deleting a configuration. You can delete a template to disable the configuration.

3.5 roles

[Role homepage ]:

The role homepage displays a list of roles, which can be super administrator or non-Super administrator;

The super administrator role is not displayed;

Ø the super administrator can view all non-Super administrator roles. The non-Super administrator can only view the roles created by the current role user;

You can add or edit roles. role management can be performed only when you select whether to be a system administrator when creating a user.

[Create a role ]:

Enter the role name for the new role. The selected permissions are the permissions of the current user;

The new role can be assigned to the new user as a subordinate role of the user;

The Parent-level permission is the added permission for creating an application. After an environment is added, the Environment permission for the application is added accordingly, for a role other than the super administrator, You must select this permission to view the application or the permission. Save the role.

[Edit role]: The operation is the same as creating a role. You can modify the role name and permissions.

3.6 users

Manage the user homepage and display all users. You can create and edit users.

 

[New User]: Enter the name, user name, and password, and select the role (with the corresponding role permissions, and the role that can be selected is the role created by the current Login User ), select whether to be a system administrator (the system administrator has the permissions to create a user and create a role) and save the settings.

[Edit user]: The operation is the same as creating a user. Save and modify the operation.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.