Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
be262f10
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
be262f10
编写于
5月 14, 2020
作者:
kimmking
提交者:
GitHub
5月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5599 from yanyzy/dev
Support shadow rule persistence to config center
上级
0ecfe168
6c1ebb11
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
195 addition
and
2 deletion
+195
-2
examples/example-core/config-utility/src/main/java/org/apache/shardingsphere/example/type/ShardingType.java
.../org/apache/shardingsphere/example/type/ShardingType.java
+3
-1
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/JavaConfigurationExampleMain.java
.../orchestration/raw/jdbc/JavaConfigurationExampleMain.java
+6
-0
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/YamlConfigurationExampleMain.java
.../orchestration/raw/jdbc/YamlConfigurationExampleMain.java
+4
-0
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/RegistryCenterConfigurationUtil.java
...tion/raw/jdbc/config/RegistryCenterConfigurationUtil.java
+7
-0
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShadowConfiguration.java
...ation/raw/jdbc/config/cloud/CloudShadowConfiguration.java
+42
-0
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShadowConfiguration.java
...ation/raw/jdbc/config/local/LocalShadowConfiguration.java
+61
-0
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/resources/META-INF/zookeeper/cloud/shadow.yaml
...e/src/main/resources/META-INF/zookeeper/cloud/shadow.yaml
+25
-0
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/resources/META-INF/zookeeper/local/shadow.yaml
...e/src/main/resources/META-INF/zookeeper/local/shadow.yaml
+46
-0
sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java
...gsphere/orchestration/core/configcenter/ConfigCenter.java
+1
-1
未找到文件。
examples/example-core/config-utility/src/main/java/org/apache/shardingsphere/example/type/ShardingType.java
浏览文件 @
be262f10
...
...
@@ -29,5 +29,7 @@ public enum ShardingType {
SHARDING_MASTER_SLAVE
,
ENCRYPT
ENCRYPT
,
SHADOW
}
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/JavaConfigurationExampleMain.java
浏览文件 @
be262f10
...
...
@@ -24,9 +24,11 @@ import org.apache.shardingsphere.example.core.jdbc.service.OrderServiceImpl;
import
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.RegistryCenterConfigurationUtil
;
import
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudEncryptConfiguration
;
import
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudMasterSlaveConfiguration
;
import
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudShadowConfiguration
;
import
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudShardingDatabasesAndTablesConfiguration
;
import
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalEncryptConfiguration
;
import
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalMasterSlaveConfiguration
;
import
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalShadowConfiguration
;
import
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalShardingDatabasesAndTablesConfiguration
;
import
org.apache.shardingsphere.example.type.RegistryCenterType
;
import
org.apache.shardingsphere.example.type.ShardingType
;
...
...
@@ -47,6 +49,7 @@ public class JavaConfigurationExampleMain {
private
static
ShardingType
shardingType
=
ShardingType
.
SHARDING_DATABASES_AND_TABLES
;
// private static ShardingType shardingType = ShardingType.MASTER_SLAVE;
// private static ShardingType shardingType = ShardingType.ENCRYPT;
// private static ShardingType shardingType = ShardingType.SHADOW;
private
static
boolean
loadConfigFromRegCenter
=
false
;
// private static boolean loadConfigFromRegCenter = true;
...
...
@@ -77,6 +80,9 @@ public class JavaConfigurationExampleMain {
case
ENCRYPT:
configuration
=
loadConfigFromRegCenter
?
new
CloudEncryptConfiguration
(
centerConfigurationMap
)
:
new
LocalEncryptConfiguration
(
centerConfigurationMap
);
break
;
case
SHADOW:
configuration
=
loadConfigFromRegCenter
?
new
CloudShadowConfiguration
(
centerConfigurationMap
)
:
new
LocalShadowConfiguration
(
centerConfigurationMap
);
break
;
default
:
throw
new
UnsupportedOperationException
(
shardingType
.
name
());
}
...
...
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/YamlConfigurationExampleMain.java
浏览文件 @
be262f10
...
...
@@ -40,6 +40,7 @@ public class YamlConfigurationExampleMain {
private
static
ShardingType
shardingType
=
ShardingType
.
SHARDING_DATABASES_AND_TABLES
;
// private static ShardingType shardingType = ShardingType.MASTER_SLAVE;
// private static ShardingType shardingType = ShardingType.ENCRYPT;
// private static ShardingType shardingType = ShardingType.SHADOW;
private
static
boolean
loadConfigFromRegCenter
=
false
;
// private static boolean loadConfigFromRegCenter = true;
...
...
@@ -68,6 +69,9 @@ public class YamlConfigurationExampleMain {
case
ENCRYPT:
yamlFilePath
=
String
.
format
(
"/META-INF/%s/%s/encrypt.yaml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
return
YamlOrchestrationShardingSphereDataSourceFactory
.
createDataSource
(
getFile
(
yamlFilePath
));
case
SHADOW:
yamlFilePath
=
String
.
format
(
"/META-INF/%s/%s/shadow.yaml"
,
registryCenterType
.
name
().
toLowerCase
(),
loadConfigFromRegCenter
?
"cloud"
:
"local"
);
return
YamlOrchestrationShardingSphereDataSourceFactory
.
createDataSource
(
getFile
(
yamlFilePath
));
default
:
throw
new
UnsupportedOperationException
(
shardingType
.
name
());
}
...
...
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/RegistryCenterConfigurationUtil.java
浏览文件 @
be262f10
...
...
@@ -52,6 +52,9 @@ public class RegistryCenterConfigurationUtil {
case
ENCRYPT:
instanceConfigurationMap
.
put
(
"orchestration-encrypt-data-source"
,
result
);
break
;
case
SHADOW:
instanceConfigurationMap
.
put
(
"orchestration-shadow-data-source"
,
result
);
break
;
}
return
instanceConfigurationMap
;
}
...
...
@@ -85,6 +88,10 @@ public class RegistryCenterConfigurationUtil {
instanceConfigurationMap
.
put
(
"orchestration-encrypt-data-source"
,
nacosResult
);
instanceConfigurationMap
.
put
(
"orchestration-zookeeper-encrypt-data-source"
,
zookeeperResult
);
break
;
case
SHADOW:
instanceConfigurationMap
.
put
(
"orchestration-shadow-data-source"
,
nacosResult
);
instanceConfigurationMap
.
put
(
"orchestration-zookeeper-shadow-data-source"
,
zookeeperResult
);
break
;
}
return
instanceConfigurationMap
;
}
...
...
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShadowConfiguration.java
0 → 100644
浏览文件 @
be262f10
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud
;
import
org.apache.shardingsphere.example.config.ExampleConfiguration
;
import
org.apache.shardingsphere.orchestration.center.config.CenterConfiguration
;
import
org.apache.shardingsphere.orchestration.center.config.OrchestrationConfiguration
;
import
org.apache.shardingsphere.shardingjdbc.orchestration.api.OrchestrationShardingSphereDataSourceFactory
;
import
javax.sql.DataSource
;
import
java.sql.SQLException
;
import
java.util.Map
;
public
class
CloudShadowConfiguration
implements
ExampleConfiguration
{
private
final
Map
<
String
,
CenterConfiguration
>
centerConfigurationMap
;
public
CloudShadowConfiguration
(
final
Map
<
String
,
CenterConfiguration
>
centerConfigurationMap
)
{
this
.
centerConfigurationMap
=
centerConfigurationMap
;
}
@Override
public
DataSource
getDataSource
()
throws
SQLException
{
return
OrchestrationShardingSphereDataSourceFactory
.
createDataSource
(
new
OrchestrationConfiguration
(
centerConfigurationMap
));
}
}
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShadowConfiguration.java
0 → 100644
浏览文件 @
be262f10
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local
;
import
org.apache.shardingsphere.example.config.ExampleConfiguration
;
import
org.apache.shardingsphere.example.core.api.DataSourceUtil
;
import
org.apache.shardingsphere.orchestration.center.config.CenterConfiguration
;
import
org.apache.shardingsphere.orchestration.center.config.OrchestrationConfiguration
;
import
org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration
;
import
org.apache.shardingsphere.shardingjdbc.orchestration.api.OrchestrationShardingSphereDataSourceFactory
;
import
javax.sql.DataSource
;
import
java.sql.SQLException
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
public
class
LocalShadowConfiguration
implements
ExampleConfiguration
{
private
final
Map
<
String
,
CenterConfiguration
>
centerConfigurationMap
;
public
LocalShadowConfiguration
(
final
Map
<
String
,
CenterConfiguration
>
centerConfigurationMap
)
{
this
.
centerConfigurationMap
=
centerConfigurationMap
;
}
@Override
public
DataSource
getDataSource
()
throws
SQLException
{
return
OrchestrationShardingSphereDataSourceFactory
.
createDataSource
(
createDataSourceMap
(),
Collections
.
singleton
(
getShadowRuleConfiguration
()),
new
Properties
(),
getOrchestrationConfiguration
());
}
private
Map
<
String
,
DataSource
>
createDataSourceMap
()
{
Map
<
String
,
DataSource
>
result
=
new
HashMap
<>();
result
.
put
(
"ds"
,
DataSourceUtil
.
createDataSource
(
"ds"
));
result
.
put
(
"shadow_ds"
,
DataSourceUtil
.
createDataSource
(
"shadow_ds"
));
return
result
;
}
private
OrchestrationConfiguration
getOrchestrationConfiguration
()
{
return
new
OrchestrationConfiguration
(
centerConfigurationMap
);
}
private
ShadowRuleConfiguration
getShadowRuleConfiguration
()
{
return
new
ShadowRuleConfiguration
(
"shadow"
,
Collections
.
singletonMap
(
"ds"
,
"shadow_ds"
));
}
}
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/resources/META-INF/zookeeper/cloud/shadow.yaml
0 → 100644
浏览文件 @
be262f10
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
orchestration
:
demo_yaml_ds_shadow
:
orchestrationType
:
config_center,registry_center,metadata_center
instanceType
:
zookeeper
serverLists
:
localhost:2181
namespace
:
orchestration-yaml-demo
props
:
overwrite
:
false
examples/sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/resources/META-INF/zookeeper/local/shadow.yaml
0 → 100644
浏览文件 @
be262f10
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
orchestration
:
demo_yaml_ds_shadow
:
orchestrationType
:
config_center,registry_center,metadata_center
instanceType
:
zookeeper
serverLists
:
localhost:2181
namespace
:
orchestration-yaml-demo
props
:
overwrite
:
true
dataSources
:
ds
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/ds
username
:
root
password
:
ds_0
:
!!com.zaxxer.hikari.HikariDataSource
driverClassName
:
com.mysql.jdbc.Driver
jdbcUrl
:
jdbc:mysql://localhost:3306/shadow_ds
username
:
root
password
:
rules
:
-
!!org.apache.shardingsphere.sharding.core.yaml.config.shadow.YamlShadowRuleConfiguration
column
:
shadow
shadowMappings
:
ds
:
ds_0
props
:
sql.show
:
true
sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-configcenter/src/main/java/org/apache/shardingsphere/orchestration/core/configcenter/ConfigCenter.java
浏览文件 @
be262f10
...
...
@@ -129,7 +129,7 @@ public final class ConfigCenter {
}
else
if
(
each
instanceof
ShadowRuleConfiguration
)
{
ShadowRuleConfiguration
config
=
(
ShadowRuleConfiguration
)
each
;
Preconditions
.
checkState
(!
config
.
getColumn
().
isEmpty
()
&&
null
!=
config
.
getShadowMappings
(),
"No available shadow rule configuration in `%s` for orchestration."
,
shardingSchemaName
);
// TODO process shadow
configurations
.
add
(
each
);
}
}
repository
.
persist
(
node
.
getRulePath
(
shardingSchemaName
),
YamlEngine
.
marshal
(
new
RuleRootConfigurationsYamlSwapper
().
swap
(
configurations
)));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录