ZooKeeper configuration

Updated at:

This topic describes how to use the dynamic configuration plug-in provided by SOFAArk to control the lifecycle of Biz by using ZooKeeper.

Introduce dependencies

SOFAArk provides config-ark-plugin configuration center to connect to ZooKeeper to run time accept configurations and control the lifecycle of Biz. The introduced dependencies are as follows:

<dependency>
     <groupId>com.alipay.sofa</groupId>
     <artifactId>config-ark-plugin</artifactId>
     <version>${sofa.ark.version}</version>
</dependency>

Configure the ZooKeeper address

Add the following configuration to the SOFAArk configuration file conf/ark/bootstrap.properties. For more information, see Configure SOFAArk.

com.alipay.sofa.ark.config.address=zookeeper:<ip:port> // Enter the ZooKeeper IP address and port number.

Configuration dimension

After SOFAArk is started, two node configurations are registered in Zookeeper: host application and IP address.

  • sofa-ark/${com.alipay.sofa.ark.master.biz}/: The dimension configuration of the host application. When the application is started, the dimension configuration is pulled to control the deployment of related Biz. After the application is restarted, the configuration is not lost.

  • sofa-ark/${com.alipay.sofa.ark.master.biz}/ip/: IP dimension configuration, lost after application restart, is usually used to control the Biz behavior of a single machine at runtime.

By writing the configuration of these two nodes, you can control the Biz run time state of the relevant machines and applications.

Configuration form

Dynamic configuration uses the state declaration command. After SOFAArk receives the configuration, it parses the command (including install, uninstall, and switch) based on the state description. The command format is as follows:

bizName:bizVersion:bizState?k1=v1&k2=v2

Separate multiple instructions with semicolon (;). A single instruction consists of the Biz name, Biz version, Biz expected status, and parameters. The status configuration describes the status of all non-host Biz after the instruction is pushed.

For example, two applications A and B are deployed in the SOFAArk container. The versions of these applications are 1.0. Application A is the host application. Because the host application cannot be uninstalled, you do not need to consider the host application. You can simply assume that the Biz state of the current container is declared as follows:

`B:1.0:Activated`

If you want to install the C application at this time, the version is 1.0, and the file stream address is urlC, then the push instruction should be:

B:1.0:Activated;C:1.0:Activated?bizUrl=urlC

If you want to install the B application, the version is 2.0, the file stream address is urlB, and you want the 2.0 version to be activated, then the command you push should be:

B:1.0:Deactivated;B:2.0:Actaivated?bizUrl=urlB;C:1.0:Activated
Note
  • SOFAArk allows only one version of an application to be active. If other versions exist, the application must be inactive. So when you want to activate the B app 2.0 version, the B app 1.0 version should be declared inactive.

  • Currently, you may need to configure the BizUrl parameter only when you install a new Biz file. This parameter is used to specify the Biz file stream address. In other scenarios, parsing the parameter is meaningless. So, when you install application B, you can omit the urlC parameter.

If you want to uninstall the 2.0 version of the B application, activate the 1.0 version of the B application, and uninstall the C application, the pushed instruction is declared as follows:

B:1.0:Activated

According to the preceding operation description, when pushing dynamic configurations, you only need to declare the desired Biz state. SOFAArk infers specific execution instructions based on the state declaration and tries to maintain service continuity as much as possible. Taking the last operation as an example, SOFAArk infers the following sequence of execution instructions:

  1. Execute the switch command to activate the 1.0 version of the B application and passivate the 2.0 version of the B application to ensure service continuity.

  2. Execute the uninstall command to uninstall the 2.0 version of the B application.

  3. Execute the uninstall command to uninstall the C application version 1.0.

Precautions

  • Currently, it is only possible to use the instruction parameter BizUrl to specify the Biz file stream address when installing a new Biz. A file stream address string is a URL object that can be directly constructed, such as file://xxx or http://xxx. When you install a new Biz, the bizUrl parameter is not required.

  • SOFAArk provides the following extension points to extend the implementation and return Biz files based on the Biz name and Biz version.

    @Extensible
    public interface BizFileGenerator{
    File createBizFile(String bizName,String bizVersion);
    }