Unverified Commit 94d8dc67 authored by 张亮's avatar 张亮 Committed by GitHub
Browse files

Merge pull request #1047 from tristaZero/dev

Add the new feature of config the proxy config.yaml 
parents 10eeaf08 9816a9eb
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -45,7 +45,9 @@ public final class Bootstrap {
    
    private static final int DEFAULT_PORT = 3307;
    
    private static final String CONFIG_YAML = "/conf/config.yaml";
    private static final String DEFAULT_CONFIG_PATH = "/conf/";
    
    private static final String DEFAULT_CONFIG_FILE = "config.yaml";
    
    /**
     * Main Entrance.
@@ -55,7 +57,7 @@ public final class Bootstrap {
     * @throws IOException IO exception
     */
    public static void main(final String[] args) throws InterruptedException, IOException {
        OrchestrationProxyConfiguration localConfig = loadLocalConfiguration(new File(Bootstrap.class.getResource(CONFIG_YAML).getFile()));
        OrchestrationProxyConfiguration localConfig = loadLocalConfiguration(new File(Bootstrap.class.getResource(getConfig(args)).getFile()));
        int port = getPort(args);
        if (null == localConfig.getOrchestration()) {
            startWithoutRegistryCenter(localConfig, port);
@@ -70,7 +72,7 @@ public final class Bootstrap {
                InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8")
        ) {
            OrchestrationProxyConfiguration result = new Yaml(new Constructor(OrchestrationProxyConfiguration.class)).loadAs(inputStreamReader, OrchestrationProxyConfiguration.class);
            Preconditions.checkNotNull(result, String.format("Configuration file `%s` is invalid.", CONFIG_YAML));
            Preconditions.checkNotNull(result, String.format("Configuration file `%s` is invalid.", yamlFile.getName()));
            Preconditions.checkState(!result.getDataSources().isEmpty(), "Data sources configuration can not be empty.");
            Preconditions.checkState(null != result.getShardingRule() || null != result.getMasterSlaveRule() || null != result.getOrchestration(), 
                    "Configuration invalid, sharding rule, local and orchestration configuration can not be both null.");
@@ -90,6 +92,13 @@ public final class Bootstrap {
        }
    }
    
    private static String getConfig(final String[] args) {
        if (2 != args.length) {
            return DEFAULT_CONFIG_PATH + DEFAULT_CONFIG_FILE;
        }
        return DEFAULT_CONFIG_PATH + args[1];
    }
    
    private static void startWithoutRegistryCenter(final OrchestrationProxyConfiguration config, final int port) throws InterruptedException, MalformedURLException {
        RuleRegistry.getInstance().init(config);
        AtomikosXaTransaction.init();
+10 −2
Original line number Diff line number Diff line
@@ -6,10 +6,18 @@ set CLASS_PATH="..;..\conf;..\lib\*"

set PORT=%1

set CONFIG=%2

if "%PORT%"=="" (
set MAIN_CLASS=io.shardingsphere.proxy.Bootstrap
) else (
) else ( if "%CONFIG%"=="" (
    set MAIN_CLASS=io.shardingsphere.proxy.Bootstrap %PORT%
    echo The port is configured as %PORT%
    ) else (
    set MAIN_CLASS=io.shardingsphere.proxy.Bootstrap %PORT% %CONFIG%
    echo The port is configured as %PORT%
    echo The configuration file is %CONFIG%
    )
)

java -server -Xmx2g -Xms2g -Xmn1g -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 -Dfile.encoding=UTF-8 -classpath %CLASS_PATH% %MAIN_CLASS%
+9 −1
Original line number Diff line number Diff line
@@ -26,11 +26,19 @@ JAVA_MEM_OPTS=" -server -Xmx2g -Xms2g -Xmn1g -Xss256k -XX:+DisableExplicitGC -XX

MAIN_CLASS=io.shardingsphere.proxy.Bootstrap

echo "Starting the $SERVER_NAME ..."

if [ $# == 1 ]; then
    MAIN_CLASS=$MAIN_CLASS" "$1
    echo "The port is configured as $1"
fi

if [ $# == 2 ]; then
    MAIN_CLASS=$MAIN_CLASS" "$1" "$2
    echo "The port is configured as $1"
    echo "The configuration file is $DEPLOY_DIR/conf/$2"
fi

echo "Starting the $SERVER_NAME ..."
nohup java $JAVA_OPTS $JAVA_MEM_OPTS -classpath $CLASS_PATH $MAIN_CLASS > $STDOUT_FILE 2>&1 &
sleep 1
echo "Please check the STDOUT file: $STDOUT_FILE"
+3 −45
Original line number Diff line number Diff line
##################      ##################
# Here you can configure the rules for the proxy.
#
# We provide two kinds of configurations for example. The one is the configuration of Sharding rule,
# and the other is the configuration of master-slave rule.
# If you want to use Sharding, please refer to the first one, and if you only want to use master-slave,
# please refer to the second one.
# We provide two kinds of configurations for example. This one is the configuration of Sharding rule,
# If you want to use Sharding, please refer to the this one, and if you only want to use master-slave,
# please refer to config_master_slave.yaml.
#
##################      ##################


# The example of Sharding rule.

#dataSources:
@@ -66,46 +64,6 @@
#    proxy.max.working.threads: 16
#    sql.show: false


# The example of master-slave rule.

#dataSources:
#  ds_0:
#    url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false
#    username: root
#    password:
#    autoCommit: true
#    connectionTimeout: 30000
#    idleTimeout: 60000
#    maxLifetime: 1800000
#    maximumPoolSize: 65
#  ds_1:
#    url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false
#    username: root
#    password:
#    autoCommit: true
#    connectionTimeout: 30000
#    idleTimeout: 60000
#    maxLifetime: 1800000
#    maximumPoolSize: 65
#masterSlaveRule:
#  name: ds_ms
#  masterDataSourceName: ds_0
#  slaveDataSourceNames:
#    - ds_1
#  props:
#    # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database.
#    #                  The benefit of this approach is saving memory for Proxy by Stream ResultSet.
#    # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet.
#    #                      Meanwhile, the cost of the memory will be increased.
#    proxy.mode: MEMORY_STRICTLY
#    proxy.transaction.mode: NONE
#    proxy.max.working.threads: 16
#    sql.show: false


# Common configurations.

#orchestration:
#  name: orchestration_ds
#  type: SHARDING
+57 −0
Original line number Diff line number Diff line
##################      ##################
# Here you can configure the rules for the proxy.
#
# We provide two kinds of configurations for example. This one is the configuration of Master slave rule,
# If you only want to use master-slave, please refer to this one, and if you want to use Sharding,
# please refer to the config.yaml.
#
##################      ##################


# The example of master-slave rule.

#dataSources:
#  ds_0:
#    url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false
#    username: root
#    password:
#    autoCommit: true
#    connectionTimeout: 30000
#    idleTimeout: 60000
#    maxLifetime: 1800000
#    maximumPoolSize: 65
#  ds_1:
#    url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false
#    username: root
#    password:
#    autoCommit: true
#    connectionTimeout: 30000
#    idleTimeout: 60000
#    maxLifetime: 1800000
#    maximumPoolSize: 65
#masterSlaveRule:
#  name: ds_ms
#  masterDataSourceName: ds_0
#  slaveDataSourceNames:
#    - ds_1
#  props:
#    # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database.
#    #                  The benefit of this approach is saving memory for Proxy by Stream ResultSet.
#    # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet.
#    #                      Meanwhile, the cost of the memory will be increased.
#    proxy.mode: MEMORY_STRICTLY
#    proxy.transaction.mode: NONE
#    proxy.max.working.threads: 16
#    sql.show: false

#orchestration:
#  name: orchestration_ds
#  type: SHARDING
#  overwrite: true
#  zookeeper:
#    namespace: orchestration
#    serverLists: localhost:2181

#proxyAuthority:
#  username: root
#  password: root