未验证 提交 06a81bf2 编写于 作者: L Liang Zhang 提交者: GitHub

Remove shardingsphere-orchestration-repository-common (#6488)

* For checkstyle

* Refactor common yaml package

* Move orche yaml to core module

* Move OrchestrationException to api package

* Use DataChangedEvent.ChangedType only on import statement

* Refactor repository

* Remove ConfigKeyUtils

* Remove shardingsphere-orchestration-repository-common
上级 4894291f
......@@ -49,7 +49,7 @@ sql.show: true
多个数据库连接池的集合,不同数据库连接池属性自适配(例如:DBCP,C3P0,Druid, HikariCP)。
```yaml
ds_0: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration
ds_0: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
props:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
......@@ -61,7 +61,7 @@ ds_0: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDa
minPoolSize: 1
username: root
maxLifetimeMilliseconds: 1800000
ds_1: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration
ds_1: !!org.apache.shardingsphere.orchestration.core.common.yaml.configYamlDataSourceConfiguration
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
props:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
......
......@@ -49,7 +49,7 @@ sql.show: true
A collection of multiple database connection pools, whose properties (e.g. DBCP, C3P0, Druid and HikariCP) are configured by users themselves.
```yaml
ds_0: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration
ds_0: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
props:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
......@@ -61,7 +61,7 @@ ds_0: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDa
minPoolSize: 1
username: root
maxLifetimeMilliseconds: 1800000
ds_1: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration
ds_1: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
props:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
......
......@@ -33,7 +33,7 @@ curl -X POST \
-H 'content-type: application/json' \
-d '{
"ruleConfiguration": {
"sourceDatasource": "ds_0: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n username: root\n password: '\''123456'\'keyGenerateStrategy
"sourceDatasource": "ds_0: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n username: root\n password: '\''123456'\'keyGenerateStrategy
```
更多管理接口详情请参见[使用手册](/cn/user-manual/shardingsphere-scaling/usage/)
......@@ -33,7 +33,7 @@ curl -X POST \
-H 'content-type: application/json' \
-d '{
"ruleConfiguration": {
"sourceDatasource": "ds_0: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n username: root\n password: '\''123456'\'keyGenerateStrategy
"sourceDatasource": "ds_0: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n username: root\n password: '\''123456'\'keyGenerateStrategy
```
Please refer to [Configuration Manual](/en/user-manual/shardingsphere-scaling/usage/) for more details.
......@@ -15,10 +15,11 @@
* limitations under the License.
*/
package org.apache.shardingsphere.orchestration.core.common.configuration;
package org.apache.shardingsphere.orchestration.core.common.yaml.swapper;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration;
/**
* Data source configuration YAML swapper.
......
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package org.apache.shardingsphere.orchestration.repository.common.yaml.swapper;
package org.apache.shardingsphere.orchestration.core.common.yaml.swapper;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
......
......@@ -15,12 +15,12 @@
* limitations under the License.
*/
package org.apache.shardingsphere.orchestration.repository.common.yaml.swapper;
package org.apache.shardingsphere.orchestration.core.common.yaml.swapper;
import org.apache.shardingsphere.infra.yaml.swapper.YamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
/**
* Orchestration configuration YAML swapper.
......
......@@ -17,10 +17,11 @@
package org.apache.shardingsphere.orchestration.core.common.listener;
import org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent;
import org.apache.shardingsphere.orchestration.repository.api.OrchestrationRepository;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEventListener;
import org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEvent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
......@@ -54,10 +55,10 @@ public final class PostOrchestrationRepositoryEventListenerTest {
};
doAnswer(invocationOnMock -> {
DataChangedEventListener listener = (DataChangedEventListener) invocationOnMock.getArguments()[1];
listener.onChange(new DataChangedEvent("test", "value", DataChangedEvent.ChangedType.UPDATED));
listener.onChange(new DataChangedEvent("test", "value", ChangedType.UPDATED));
return mock(DataChangedEventListener.class);
}).when(orchestrationRepository).watch(anyString(), any(DataChangedEventListener.class));
postEventListener.watch(DataChangedEvent.ChangedType.UPDATED);
postEventListener.watch(ChangedType.UPDATED);
verify(orchestrationRepository).watch(eq("test"), ArgumentMatchers.any());
}
......@@ -72,10 +73,10 @@ public final class PostOrchestrationRepositoryEventListenerTest {
};
doAnswer(invocationOnMock -> {
DataChangedEventListener listener = (DataChangedEventListener) invocationOnMock.getArguments()[1];
listener.onChange(new DataChangedEvent("test", "value", DataChangedEvent.ChangedType.UPDATED));
listener.onChange(new DataChangedEvent("test", "value", ChangedType.UPDATED));
return mock(DataChangedEventListener.class);
}).when(orchestrationRepository).watch(anyString(), any(DataChangedEventListener.class));
postEventListener.watch(DataChangedEvent.ChangedType.UPDATED, DataChangedEvent.ChangedType.DELETED);
postEventListener.watch(ChangedType.UPDATED, ChangedType.DELETED);
verify(orchestrationRepository).watch(eq("test"), ArgumentMatchers.any());
verify(orchestrationRepository).watch(eq("dev"), ArgumentMatchers.any());
}
......
......@@ -15,9 +15,10 @@
* limitations under the License.
*/
package org.apache.shardingsphere.orchestration.core.common.configuration;
package org.apache.shardingsphere.orchestration.core.common.yaml.swapper;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
......
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package org.apache.shardingsphere.orchestration.repository.common.yaml.swapper;
package org.apache.shardingsphere.orchestration.core.common.yaml.swapper;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.junit.Test;
......
......@@ -15,12 +15,12 @@
* limitations under the License.
*/
package org.apache.shardingsphere.orchestration.repository.common.yaml.swapper;
package org.apache.shardingsphere.orchestration.core.common.yaml.swapper;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
import org.junit.Test;
import java.util.Properties;
......
......@@ -42,8 +42,8 @@ import org.apache.shardingsphere.metrics.configuration.config.MetricsConfigurati
import org.apache.shardingsphere.metrics.configuration.swapper.MetricsConfigurationYamlSwapper;
import org.apache.shardingsphere.metrics.configuration.yaml.YamlMetricsConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.orchestration.core.common.configuration.DataSourceConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.swapper.DataSourceConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
......@@ -224,7 +224,7 @@ public final class ConfigCenter {
* @param shardingSchemaName sharding schema name
* @return data source configurations
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
public Map<String, DataSourceConfiguration> loadDataSourceConfigurations(final String shardingSchemaName) {
if (!hasDataSourceConfiguration(shardingSchemaName)) {
return new LinkedHashMap<>();
......
......@@ -36,8 +36,8 @@ import org.apache.shardingsphere.orchestration.core.common.event.OrchestrationEv
import org.apache.shardingsphere.orchestration.core.common.listener.PostOrchestrationRepositoryEventListener;
import org.apache.shardingsphere.orchestration.core.config.ConfigCenter;
import org.apache.shardingsphere.orchestration.core.config.ConfigCenterNode;
import org.apache.shardingsphere.orchestration.core.common.configuration.DataSourceConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.swapper.DataSourceConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration;
import java.util.Collection;
import java.util.HashSet;
......@@ -109,7 +109,7 @@ public final class SchemaChangedListener extends PostOrchestrationRepositoryEven
? createDataSourceChangedEvent(shardingSchemaName, event) : createRuleChangedEvent(shardingSchemaName, event);
}
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
private DataSourceChangedEvent createDataSourceChangedEvent(final String shardingSchemaName, final DataChangedEvent event) {
Map<String, YamlDataSourceConfiguration> dataSourceConfigurations = (Map) YamlEngine.unmarshal(event.getValue());
Preconditions.checkState(null != dataSourceConfigurations && !dataSourceConfigurations.isEmpty(), "No available data sources to load for orchestration.");
......
......@@ -38,7 +38,7 @@ import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfigura
import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.orchestration.core.common.utils.IpUtils;
import org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.junit.Ignore;
......
......@@ -18,9 +18,10 @@
package org.apache.shardingsphere.orchestration.core.config.listener;
import lombok.SneakyThrows;
import org.apache.shardingsphere.orchestration.core.common.event.ClusterConfigurationChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.event.ClusterConfigurationChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
......@@ -51,7 +52,7 @@ public final class ClusterConfigurationChangedListenerTest {
@Test
public void assertCreateOrchestrationEvent() {
ClusterConfigurationChangedEvent event = clusterConfigurationChangedListener
.createOrchestrationEvent(new DataChangedEvent("test", readYAML(DATA_CLUSTER_YAML), DataChangedEvent.ChangedType.UPDATED));
.createOrchestrationEvent(new DataChangedEvent("test", readYAML(DATA_CLUSTER_YAML), ChangedType.UPDATED));
assertNotNull(event);
assertNotNull(event.getClusterConfiguration());
assertNotNull(event.getClusterConfiguration().getHeartbeat());
......
......@@ -18,9 +18,10 @@
package org.apache.shardingsphere.orchestration.core.config.listener;
import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
import org.apache.shardingsphere.orchestration.core.common.event.MetricsConfigurationChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.event.MetricsConfigurationChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -51,7 +52,7 @@ public final class MetricsConfigurationChangedListenerTest {
@Test
public void assertCreateOrchestrationEvent() {
MetricsConfigurationChangedEvent event = metricsConfigurationChangedListener.createOrchestrationEvent(new DataChangedEvent("test", METRICS_YAML, DataChangedEvent.ChangedType.UPDATED));
MetricsConfigurationChangedEvent event = metricsConfigurationChangedListener.createOrchestrationEvent(new DataChangedEvent("test", METRICS_YAML, ChangedType.UPDATED));
MetricsConfiguration actual = event.getMetricsConfiguration();
assertThat(actual, notNullValue());
assertThat(actual.getMetricsName(), is("prometheus"));
......
......@@ -15,7 +15,8 @@
# limitations under the License.
#
master_ds: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration
master_ds: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
props:
url: jdbc:mysql://localhost:3306/demo_ds_master
......
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.orchestration.core.metadata.listener;
import org.apache.shardingsphere.orchestration.repository.api.OrchestrationRepository;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import java.util.Collection;
......@@ -37,6 +37,6 @@ public final class MetaDataListenerManager {
* Initialize all metadata changed listeners.
*/
public void initListeners() {
metaDataChangedListener.watch(DataChangedEvent.ChangedType.UPDATED);
metaDataChangedListener.watch(ChangedType.UPDATED);
}
}
......@@ -17,10 +17,11 @@
package org.apache.shardingsphere.orchestration.core.metadata.listener;
import org.apache.shardingsphere.orchestration.core.metadata.MetaDataTest;
import org.apache.shardingsphere.orchestration.core.metadata.event.MetaDataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.OrchestrationRepository;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.core.metadata.MetaDataTest;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
......@@ -45,7 +46,7 @@ public final class MetaDataChangedListenerTest {
@Test
public void createOrchestrationEvent() {
DataChangedEvent event = new DataChangedEvent("/test/metadata/schema", MetaDataTest.META_DATA, DataChangedEvent.ChangedType.UPDATED);
DataChangedEvent event = new DataChangedEvent("/test/metadata/schema", MetaDataTest.META_DATA, ChangedType.UPDATED);
MetaDataChangedEvent metaDataChangedEvent = (MetaDataChangedEvent) metaDataChangedListener.createOrchestrationEvent(event);
assertNotNull(metaDataChangedEvent);
assertThat(metaDataChangedEvent.getSchemaNames(), is(Collections.singleton("schema")));
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.orchestration.core.metadata.listener;
import org.apache.shardingsphere.orchestration.core.metadata.util.FieldUtil;
import org.apache.shardingsphere.orchestration.repository.api.OrchestrationRepository;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
......@@ -43,6 +43,6 @@ public final class MetaDataListenerManagerTest {
MetaDataListenerManager actual = new MetaDataListenerManager("test", orchestrationRepository, Collections.singleton("sharding_db"));
FieldUtil.setField(actual, "metaDataChangedListener", metaDataChangedListener);
actual.initListeners();
verify(metaDataChangedListener).watch(DataChangedEvent.ChangedType.UPDATED);
verify(metaDataChangedListener).watch(ChangedType.UPDATED);
}
}
......@@ -29,7 +29,6 @@
<modules>
<module>shardingsphere-orchestration-repository-api</module>
<module>shardingsphere-orchestration-repository-common</module>
<module>shardingsphere-orchestration-repository-provider</module>
</modules>
</project>
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.orchestration.repository.common.exception;
package org.apache.shardingsphere.orchestration.repository.api.exception;
/**
* Orchestration exception.
......@@ -24,10 +24,6 @@ public final class OrchestrationException extends RuntimeException {
private static final long serialVersionUID = -6417179023552012152L;
public OrchestrationException(final String errorMessage, final Object... args) {
super(String.format(errorMessage, args));
}
public OrchestrationException(final Exception cause) {
super(cause);
}
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-orchestration-repository</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
<artifactId>shardingsphere-orchestration-repository-common</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-orchestration-repository-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/*
* 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.orchestration.repository.common.util;
/**
* Config key utilities.
*/
public final class ConfigKeyUtils {
private static final String DOT_SEPARATOR = ".";
private static final String PATH_SEPARATOR = "/";
/**
* Convert path to key.
*
* @param path config path
* @return config key
*/
public static String pathToKey(final String path) {
String key = path.replace(PATH_SEPARATOR, DOT_SEPARATOR);
return key.substring(key.indexOf(DOT_SEPARATOR) + 1);
}
/**
* Convert key to path.
*
* @param key config key
* @return config path
*/
public static String keyToPath(final String key) {
return PATH_SEPARATOR + key.replace(DOT_SEPARATOR, PATH_SEPARATOR);
}
}
/*
* 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.orchestration.repository.common.exception;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class OrchestrationExceptionTest {
@Test
public void assertException() {
OrchestrationException exception = new OrchestrationException(new RuntimeException("error"));
assertThat(exception.getCause().getMessage(), is("error"));
exception = new OrchestrationException("error: %s", "Orchestration");
assertThat(exception.getMessage(), is("error: Orchestration"));
}
}
/*
* 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.orchestration.repository.common.util;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class ConfigKeyUtilsTest {
@Test
public void assertPathToKey() {
assertThat(ConfigKeyUtils.pathToKey("/orchestration_ds/config/schema/test/rule"), is("orchestration_ds.config.schema.test.rule"));
}
@Test
public void assertKeyToPath() {
assertThat(ConfigKeyUtils.keyToPath("orchestration_ds.config.schema.test.rule"), is("/orchestration_ds/config/schema/test/rule"));
}
}
......@@ -30,7 +30,7 @@
<modules>
<module>shardingsphere-orchestration-repository-zookeeper-curator</module>
<module>shardingsphere-orchestration-repository-etcd</module>
<module>shardingsphere-orchestration-repository-apollo</module>
<module>shardingsphere-orchestration-repository-nacos</module>
<module>shardingsphere-orchestration-repository-apollo</module>
</modules>
</project>
......@@ -32,11 +32,6 @@
<artifactId>shardingsphere-orchestration-repository-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-orchestration-repository-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
......
......@@ -25,12 +25,12 @@ import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.orchestration.repository.apollo.wrapper.ApolloConfigWrapper;
import org.apache.shardingsphere.orchestration.repository.apollo.wrapper.ApolloOpenApiWrapper;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEventListener;
import org.apache.shardingsphere.orchestration.repository.common.util.ConfigKeyUtils;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.apollo.wrapper.ApolloConfigWrapper;
import org.apache.shardingsphere.orchestration.repository.apollo.wrapper.ApolloOpenApiWrapper;
import java.util.Collections;
import java.util.HashMap;
......@@ -44,6 +44,10 @@ import java.util.Properties;
@Slf4j
public final class ApolloRepository implements ConfigurationRepository {
private static final String DOT_SEPARATOR = ".";
private static final String PATH_SEPARATOR = "/";
private final Map<String, DataChangedEventListener> caches = new HashMap<>();
private ApolloConfigWrapper configWrapper;
......@@ -63,8 +67,8 @@ public final class ApolloRepository implements ConfigurationRepository {
@Override
public String get(final String key) {
String value = configWrapper.getProperty(ConfigKeyUtils.pathToKey(key));
return Strings.isNullOrEmpty(value) ? openApiWrapper.getValue(ConfigKeyUtils.pathToKey(key)) : value;
String value = configWrapper.getProperty(pathToKey(key));
return Strings.isNullOrEmpty(value) ? openApiWrapper.getValue(pathToKey(key)) : value;
}
@Override
......@@ -74,46 +78,55 @@ public final class ApolloRepository implements ConfigurationRepository {
@Override
public void persist(final String key, final String value) {
openApiWrapper.persist(ConfigKeyUtils.pathToKey(key), value);
openApiWrapper.persist(pathToKey(key), value);
}
@Override
public void watch(final String key, final DataChangedEventListener dataChangedEventListener) {
String apolloKey = ConfigKeyUtils.pathToKey(key);
String apolloKey = pathToKey(key);
caches.put(apolloKey, dataChangedEventListener);
ConfigChangeListener listener = changeEvent -> {
for (String changeKey : changeEvent.changedKeys()) {
ConfigChange change = changeEvent.getChange(changeKey);
DataChangedEvent.ChangedType changedType = getChangedType(change.getChangeType());
if (DataChangedEvent.ChangedType.IGNORED == changedType) {
ChangedType changedType = getChangedType(change.getChangeType());
if (ChangedType.IGNORED == changedType) {
continue;
}
if (caches.get(changeKey) == null) {
if (!caches.containsKey(changeKey)) {
continue;
}
caches.get(changeKey).onChange(new DataChangedEvent(ConfigKeyUtils.keyToPath(changeKey), change.getNewValue(), changedType));
caches.get(changeKey).onChange(new DataChangedEvent(keyToPath(changeKey), change.getNewValue(), changedType));
}
};
configWrapper.addChangeListener(listener, Collections.singleton(apolloKey), Collections.singleton(apolloKey));
}
@Override
public void delete(final String key) {
openApiWrapper.remove(ConfigKeyUtils.pathToKey(key));
}
private DataChangedEvent.ChangedType getChangedType(final PropertyChangeType changeType) {
private ChangedType getChangedType(final PropertyChangeType changeType) {
switch (changeType) {
case ADDED:
case MODIFIED:
return DataChangedEvent.ChangedType.UPDATED;
return ChangedType.UPDATED;
case DELETED:
return DataChangedEvent.ChangedType.DELETED;
return ChangedType.DELETED;
default:
return DataChangedEvent.ChangedType.IGNORED;
return ChangedType.IGNORED;
}
}
@Override
public void delete(final String key) {
openApiWrapper.remove(pathToKey(key));
}
private String pathToKey(final String path) {
String key = path.replace(PATH_SEPARATOR, DOT_SEPARATOR);
return key.substring(key.indexOf(DOT_SEPARATOR) + 1);
}
private String keyToPath(final String key) {
return PATH_SEPARATOR + key.replace(DOT_SEPARATOR, PATH_SEPARATOR);
}
@Override
public void close() {
}
......
......@@ -23,9 +23,9 @@ import lombok.SneakyThrows;
import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.apache.shardingsphere.orchestration.repository.apollo.wrapper.ApolloConfigWrapper;
import org.apache.shardingsphere.orchestration.repository.apollo.wrapper.ApolloOpenApiWrapper;
import org.apache.shardingsphere.orchestration.repository.common.util.ConfigKeyUtils;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
......@@ -88,7 +88,7 @@ public final class ApolloRepositoryTest {
@Test
public void assertWatch() throws InterruptedException, ExecutionException, TimeoutException {
assertWatchUpdateChangedType("/test/children/1", "newValue");
assertWatchUpdateChangedType("/test/children/1", "test.children.1", "newValue");
}
@Test
......@@ -98,45 +98,45 @@ public final class ApolloRepositoryTest {
@Test
public void assertWatchUpdateChangedTypeWithExistedKey() throws InterruptedException, ExecutionException, TimeoutException {
assertWatchUpdateChangedType("/test/children/4", "newValue4");
assertWatchUpdateChangedType("/test/children/4", "test.children.4", "newValue4");
assertThat(REPOSITORY.get("/test/children/4"), is("newValue4"));
}
@Test
public void assertWatchDeletedChangedTypeWithExistedKey() throws InterruptedException, ExecutionException, TimeoutException {
assertWatchDeletedChangedType("/test/children/3");
public void assertWatchUpdateChangedTypeWithNotExistedKey() throws InterruptedException, ExecutionException, TimeoutException {
assertWatchUpdateChangedType("/test/children/newKey", "test.children.newKey", "newValue");
}
private void assertWatchDeletedChangedType(final String key) throws InterruptedException, ExecutionException, TimeoutException {
private void assertWatchUpdateChangedType(final String path, final String key, final String newValue) throws InterruptedException, ExecutionException, TimeoutException {
final SettableFuture<DataChangedEvent> future = SettableFuture.create();
REPOSITORY.watch(key, future::set);
embeddedApollo.deleteProperty("orchestration", ConfigKeyUtils.pathToKey(key));
REPOSITORY.watch(path, future::set);
embeddedApollo.addOrModifyProperty("orchestration", key, newValue);
DataChangedEvent changeEvent = future.get(5, TimeUnit.SECONDS);
assertThat(changeEvent.getKey(), is(key));
assertNull(changeEvent.getValue());
assertThat(changeEvent.getChangedType(), is(DataChangedEvent.ChangedType.DELETED));
assertNull(REPOSITORY.get(key));
assertThat(changeEvent.getKey(), is(path));
assertThat(changeEvent.getValue(), is(newValue));
assertThat(changeEvent.getChangedType(), is(ChangedType.UPDATED));
}
@Test
public void assertWatchUpdateChangedTypeWithNotExistedKey() throws InterruptedException, ExecutionException, TimeoutException {
assertWatchUpdateChangedType("/test/children/newKey", "newValue");
public void assertWatchDeletedChangedTypeWithExistedKey() throws InterruptedException, ExecutionException, TimeoutException {
assertWatchDeletedChangedType("/test/children/3", "test.children.3");
}
private void assertWatchUpdateChangedType(final String key, final String newValue) throws InterruptedException, ExecutionException, TimeoutException {
private void assertWatchDeletedChangedType(final String path, final String key) throws InterruptedException, ExecutionException, TimeoutException {
final SettableFuture<DataChangedEvent> future = SettableFuture.create();
REPOSITORY.watch(key, future::set);
embeddedApollo.addOrModifyProperty("orchestration", ConfigKeyUtils.pathToKey(key), newValue);
REPOSITORY.watch(path, future::set);
embeddedApollo.deleteProperty("orchestration", key);
DataChangedEvent changeEvent = future.get(5, TimeUnit.SECONDS);
assertThat(changeEvent.getKey(), is(key));
assertThat(changeEvent.getValue(), is(newValue));
assertThat(changeEvent.getChangedType(), is(DataChangedEvent.ChangedType.UPDATED));
assertThat(changeEvent.getKey(), is(path));
assertNull(changeEvent.getValue());
assertThat(changeEvent.getChangedType(), is(ChangedType.DELETED));
assertNull(REPOSITORY.get(path));
}
@Test
public void assertDelete() {
REPOSITORY.delete("/test/children/2");
verify(OPEN_API_WRAPPER).remove(ConfigKeyUtils.pathToKey("/test/children/2"));
verify(OPEN_API_WRAPPER).remove("test.children.2");
}
@Test
......@@ -147,7 +147,7 @@ public final class ApolloRepositoryTest {
@Test
public void assertPersist() {
REPOSITORY.persist("/test/children/6", "value6");
verify(OPEN_API_WRAPPER).persist(ConfigKeyUtils.pathToKey("/test/children/6"), "value6");
verify(OPEN_API_WRAPPER).persist("test.children.6", "value6");
}
@Test
......
......@@ -23,7 +23,6 @@ import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;
import lombok.SneakyThrows;
import org.apache.shardingsphere.orchestration.repository.apollo.ApolloProperties;
import org.apache.shardingsphere.orchestration.repository.apollo.ApolloPropertyKey;
import org.apache.shardingsphere.orchestration.repository.common.util.ConfigKeyUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -74,28 +73,28 @@ public final class ApolloOpenApiWrapperTest {
@Test
public void getValue() {
apolloOpenApiWrapper.getValue(ConfigKeyUtils.pathToKey("/test/children/0"));
apolloOpenApiWrapper.getValue("test.children.0");
verify(client).getItem(ApolloPropertyKey.APP_ID.getDefaultValue(), ApolloPropertyKey.ENV.getDefaultValue(),
ApolloPropertyKey.CLUSTER_NAME.getDefaultValue(), NAME_SPACE, ConfigKeyUtils.pathToKey("/test/children/0"));
ApolloPropertyKey.CLUSTER_NAME.getDefaultValue(), NAME_SPACE, "test.children.0");
}
@Test
public void getValueNotNull() {
when(client.getItem(ApolloPropertyKey.APP_ID.getDefaultValue(), ApolloPropertyKey.ENV.getDefaultValue(),
ApolloPropertyKey.CLUSTER_NAME.getDefaultValue(), NAME_SPACE, ConfigKeyUtils.pathToKey("/test/children/0"))).thenReturn(openItemDTO);
assertNull(apolloOpenApiWrapper.getValue(ConfigKeyUtils.pathToKey("/test/children/0")));
ApolloPropertyKey.CLUSTER_NAME.getDefaultValue(), NAME_SPACE, "test.children.0")).thenReturn(openItemDTO);
assertNull(apolloOpenApiWrapper.getValue("test.children.0"));
}
@Test
public void persist() {
apolloOpenApiWrapper.persist(ConfigKeyUtils.pathToKey("/test/children/0"), "value0");
apolloOpenApiWrapper.persist("test.children.0", "value0");
verify(client).createOrUpdateItem(anyString(), anyString(), anyString(), anyString(), any(OpenItemDTO.class));
verify(client).publishNamespace(anyString(), anyString(), anyString(), anyString(), any(NamespaceReleaseDTO.class));
}
@Test
public void remove() {
apolloOpenApiWrapper.remove(ConfigKeyUtils.pathToKey("/test/children/0"));
verify(client).removeItem(anyString(), anyString(), anyString(), anyString(), eq(ConfigKeyUtils.pathToKey("/test/children/0")), anyString());
apolloOpenApiWrapper.remove("test.children.0");
verify(client).removeItem(anyString(), anyString(), anyString(), anyString(), eq("test.children.0"), anyString());
}
}
......@@ -36,11 +36,6 @@
<artifactId>shardingsphere-orchestration-repository-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-orchestration-repository-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.etcd</groupId>
......
......@@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.properties.TypedPropertyKey;
public enum EtcdPropertyKey implements TypedPropertyKey {
/**
* The portal url for apollo open api client.
* Time to live seconds.
*/
TIME_TO_LIVE_SECONDS("timeToLiveSeconds", "30", long.class);
......
......@@ -35,6 +35,7 @@ import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepos
import org.apache.shardingsphere.orchestration.repository.api.RegistryRepository;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEventListener;
import java.util.List;
......@@ -101,8 +102,8 @@ public final class EtcdRepository implements ConfigurationRepository, RegistryRe
public void watch(final String key, final DataChangedEventListener dataChangedEventListener) {
Watch.Listener listener = Watch.listener(response -> {
for (WatchEvent each : response.getEvents()) {
DataChangedEvent.ChangedType changedType = getEventChangedType(each);
if (DataChangedEvent.ChangedType.IGNORED != changedType) {
ChangedType changedType = getEventChangedType(each);
if (ChangedType.IGNORED != changedType) {
dataChangedEventListener.onChange(new DataChangedEvent(each.getKeyValue().getKey().toString(Charsets.UTF_8), each.getKeyValue().getValue().toString(Charsets.UTF_8), changedType));
}
}
......@@ -110,22 +111,22 @@ public final class EtcdRepository implements ConfigurationRepository, RegistryRe
client.getWatchClient().watch(ByteSequence.from(key, Charsets.UTF_8), listener);
}
@Override
public void delete(final String key) {
client.getKVClient().delete(ByteSequence.from(key, Charsets.UTF_8));
}
private DataChangedEvent.ChangedType getEventChangedType(final WatchEvent event) {
private ChangedType getEventChangedType(final WatchEvent event) {
switch (event.getEventType()) {
case PUT:
return DataChangedEvent.ChangedType.UPDATED;
return ChangedType.UPDATED;
case DELETE:
return DataChangedEvent.ChangedType.DELETED;
return ChangedType.DELETED;
default:
return DataChangedEvent.ChangedType.IGNORED;
return ChangedType.IGNORED;
}
}
@Override
public void delete(final String key) {
client.getKVClient().delete(ByteSequence.from(key, Charsets.UTF_8));
}
@Override
public void close() {
client.close();
......
......@@ -31,11 +31,6 @@
<artifactId>shardingsphere-orchestration-repository-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-orchestration-repository-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
......
......@@ -34,7 +34,7 @@ public enum NacosPropertyKey implements TypedPropertyKey {
GROUP("group", "SHARDING_SPHERE_DEFAULT_GROUP", String.class),
/**
* Nacos get config data timeout value.
* Get config data timeout value.
*/
TIMEOUT("timeout", String.valueOf(3000), long.class);
......
......@@ -28,8 +28,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEventListener;
import org.apache.shardingsphere.orchestration.repository.common.util.ConfigKeyUtils;
import java.util.List;
import java.util.Properties;
......@@ -41,6 +41,10 @@ import java.util.concurrent.Executor;
@Slf4j
public final class NacosRepository implements ConfigurationRepository {
private static final String DOT_SEPARATOR = ".";
private static final String PATH_SEPARATOR = "/";
private ConfigService configService;
private NacosProperties nacosProperties;
......@@ -76,7 +80,7 @@ public final class NacosRepository implements ConfigurationRepository {
@Override
public String get(final String key) {
try {
String dataId = ConfigKeyUtils.pathToKey(key);
String dataId = pathToKey(key);
String group = nacosProperties.getValue(NacosPropertyKey.GROUP);
long timeoutMs = nacosProperties.getValue(NacosPropertyKey.TIMEOUT);
return configService.getConfig(dataId, group, timeoutMs);
......@@ -106,7 +110,7 @@ public final class NacosRepository implements ConfigurationRepository {
@Override
public void persist(final String key, final String value) {
try {
String dataId = ConfigKeyUtils.pathToKey(key);
String dataId = pathToKey(key);
String group = nacosProperties.getValue(NacosPropertyKey.GROUP);
configService.publishConfig(dataId, group, value);
} catch (final NacosException ex) {
......@@ -123,7 +127,7 @@ public final class NacosRepository implements ConfigurationRepository {
@Override
public void watch(final String key, final DataChangedEventListener dataChangedEventListener) {
try {
String dataId = ConfigKeyUtils.pathToKey(key);
String dataId = pathToKey(key);
String group = nacosProperties.getValue(NacosPropertyKey.GROUP);
configService.addListener(dataId, group, new Listener() {
......@@ -134,7 +138,7 @@ public final class NacosRepository implements ConfigurationRepository {
@Override
public void receiveConfigInfo(final String configInfo) {
dataChangedEventListener.onChange(new DataChangedEvent(key, configInfo, DataChangedEvent.ChangedType.UPDATED));
dataChangedEventListener.onChange(new DataChangedEvent(key, configInfo, ChangedType.UPDATED));
}
});
} catch (final NacosException ex) {
......@@ -145,13 +149,18 @@ public final class NacosRepository implements ConfigurationRepository {
@Override
public void delete(final String key) {
try {
String dataId = ConfigKeyUtils.pathToKey(key);
String dataId = pathToKey(key);
configService.removeConfig(dataId, nacosProperties.getValue(NacosPropertyKey.GROUP));
} catch (NacosException ex) {
} catch (final NacosException ex) {
log.debug("Nacos remove config exception for: {}", ex.toString());
}
}
private String pathToKey(final String path) {
String key = path.replace(PATH_SEPARATOR, DOT_SEPARATOR);
return key.substring(key.indexOf(DOT_SEPARATOR) + 1);
}
@Override
public void close() {
}
......
......@@ -32,11 +32,6 @@
<artifactId>shardingsphere-orchestration-repository-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-orchestration-repository-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
......
......@@ -31,10 +31,11 @@ import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.CloseableUtils;
import org.apache.shardingsphere.orchestration.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.orchestration.repository.api.RegistryRepository;
import org.apache.shardingsphere.orchestration.repository.zookeeper.handler.CuratorZookeeperExceptionHandler;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEventListener;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.zookeeper.handler.CuratorZookeeperExceptionHandler;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException.OperationTimeoutException;
import org.apache.zookeeper.ZooDefs;
......@@ -221,48 +222,48 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
return;
}
DataChangedEvent.ChangedType changedType = getChangedType(event);
if (DataChangedEvent.ChangedType.IGNORED != changedType) {
if (ChangedType.IGNORED != changedType) {
dataChangedEventListener.onChange(new DataChangedEvent(data.getPath(), null == data.getData() ? null : new String(data.getData(), Charsets.UTF_8), changedType));
}
});
}
@Override
public void delete(final String key) {
private void addCacheData(final String cachePath) {
TreeCache cache = new TreeCache(client, cachePath);
try {
if (isExisted(key)) {
client.delete().deletingChildrenIfNeeded().forPath(key);
}
cache.start();
// CHECKSTYLE:OFF
} catch (Exception ex) {
} catch (final Exception ex) {
// CHECKSTYLE:ON
CuratorZookeeperExceptionHandler.handleException(ex);
}
caches.put(cachePath + "/", cache);
}
private DataChangedEvent.ChangedType getChangedType(final TreeCacheEvent event) {
private ChangedType getChangedType(final TreeCacheEvent event) {
switch (event.getType()) {
case NODE_ADDED:
return DataChangedEvent.ChangedType.ADDED;
return ChangedType.ADDED;
case NODE_UPDATED:
return DataChangedEvent.ChangedType.UPDATED;
return ChangedType.UPDATED;
case NODE_REMOVED:
return DataChangedEvent.ChangedType.DELETED;
return ChangedType.DELETED;
default:
return DataChangedEvent.ChangedType.IGNORED;
return ChangedType.IGNORED;
}
}
private void addCacheData(final String cachePath) {
TreeCache cache = new TreeCache(client, cachePath);
@Override
public void delete(final String key) {
try {
cache.start();
if (isExisted(key)) {
client.delete().deletingChildrenIfNeeded().forPath(key);
}
// CHECKSTYLE:OFF
} catch (final Exception ex) {
} catch (Exception ex) {
// CHECKSTYLE:ON
CuratorZookeeperExceptionHandler.handleException(ex);
}
caches.put(cachePath + "/", cache);
}
@Override
......
......@@ -29,27 +29,27 @@ import org.apache.shardingsphere.infra.properties.TypedPropertyKey;
public enum ZookeeperPropertyKey implements TypedPropertyKey {
/**
* Retry interval milliseconds when connect with zookeeper curator client.
* Retry interval milliseconds when connect with ZooKeeper curator client.
*/
RETRY_INTERVAL_MILLISECONDS("retryIntervalMilliseconds", String.valueOf(500), int.class),
/**
* Max Retry times when connect with zookeeper curator client.
* Max Retry times when connect with ZooKeeper curator client.
*/
MAX_RETRIES("maxRetries", String.valueOf(3), int.class),
/**
* Zookeeper curator client session timeout value.
* ZooKeeper client session timeout value.
*/
TIME_TO_LIVE_SECONDS("timeToLiveSeconds", String.valueOf(60), int.class),
/**
* Zookeeper curator client operation timeout value.
* ZooKeeper client operation timeout value.
*/
OPERATION_TIMEOUT_MILLISECONDS("operationTimeoutMilliseconds", String.valueOf(500), int.class),
/**
* Zookeeper curator client connection authorization schema name.
* ZooKeeper client connection authorization schema name.
*/
DIGEST("digest", "", String.class);
......
......@@ -20,13 +20,13 @@ package org.apache.shardingsphere.orchestration.repository.zookeeper.handler;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.orchestration.repository.common.exception.OrchestrationException;
import org.apache.shardingsphere.orchestration.repository.api.exception.OrchestrationException;
import org.apache.zookeeper.KeeperException.ConnectionLossException;
import org.apache.zookeeper.KeeperException.NoNodeException;
import org.apache.zookeeper.KeeperException.NodeExistsException;
/**
* Curator zookeeper exception handler.
* Curator ZooKeeper exception handler.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
......
......@@ -19,8 +19,9 @@ package org.apache.shardingsphere.orchestration.repository.zookeeper;
import org.apache.curator.framework.CuratorFramework;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.exception.OrchestrationException;
import org.apache.shardingsphere.orchestration.repository.api.exception.OrchestrationException;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.repository.api.listener.DataChangedEvent.ChangedType;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -85,7 +86,7 @@ public final class CuratorZookeeperRepositoryTest {
Thread.sleep(50L);
DataChangedEvent dataChangedEvent = dataChangedEventActual.get();
assertNotNull(dataChangedEvent);
assertThat(dataChangedEvent.getChangedType(), is(DataChangedEvent.ChangedType.UPDATED));
assertThat(dataChangedEvent.getChangedType(), is(ChangedType.UPDATED));
assertThat(dataChangedEvent.getKey(), is("/test/children_updated/1"));
assertThat(dataChangedEvent.getValue(), is("value2"));
assertThat(REPOSITORY.get("/test/children_updated/1"), is("value2"));
......@@ -103,7 +104,7 @@ public final class CuratorZookeeperRepositoryTest {
Thread.sleep(50L);
DataChangedEvent dataChangedEvent = dataChangedEventActual.get();
assertNotNull(dataChangedEvent);
assertThat(dataChangedEvent.getChangedType(), is(DataChangedEvent.ChangedType.DELETED));
assertThat(dataChangedEvent.getChangedType(), is(ChangedType.DELETED));
assertThat(dataChangedEvent.getKey(), is("/test/children_deleted/5"));
assertThat(dataChangedEvent.getValue(), is("value5"));
}
......@@ -116,7 +117,7 @@ public final class CuratorZookeeperRepositoryTest {
Thread.sleep(50L);
DataChangedEvent event = actualDataChangedEvent.get();
assertNotNull(event);
assertThat(event.getChangedType(), is(DataChangedEvent.ChangedType.ADDED));
assertThat(event.getChangedType(), is(ChangedType.ADDED));
assertThat(event.getKey(), is("/test/children_added/4"));
assertThat(event.getValue(), is("value4"));
}
......
......@@ -17,7 +17,7 @@
package org.apache.shardingsphere.orchestration.repository.zookeeper.handler;
import org.apache.shardingsphere.orchestration.repository.common.exception.OrchestrationException;
import org.apache.shardingsphere.orchestration.repository.api.exception.OrchestrationException;
import org.apache.zookeeper.KeeperException;
import org.junit.Assert;
import org.junit.Test;
......
......@@ -47,11 +47,6 @@
<artifactId>shardingsphere-orchestration-repository-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-orchestration-repository-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-cluster-facade</artifactId>
......
......@@ -27,7 +27,7 @@ import org.apache.shardingsphere.driver.orchestration.internal.util.YamlOrchestr
import org.apache.shardingsphere.driver.orchestration.internal.yaml.YamlOrchestrationRootRuleConfigurations;
import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
import javax.sql.DataSource;
import java.io.File;
......
......@@ -20,8 +20,8 @@ package org.apache.shardingsphere.driver.orchestration.internal.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.swapper.OrchestrationCenterConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.swapper.OrchestrationCenterConfigurationYamlSwapper;
/**
* YAML orchestration configuration swapper utility.
......
......@@ -21,7 +21,7 @@ import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.cluster.configuration.yaml.YamlClusterConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
/**
* YAML root rule configurations for orchestration.
......
......@@ -18,8 +18,8 @@
package org.apache.shardingsphere.driver.orchestration.internal.util;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationCenterConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
import org.junit.Test;
import java.util.Properties;
......
......@@ -24,8 +24,8 @@ import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataS
import org.apache.shardingsphere.driver.orchestration.internal.datasource.OrchestrationShardingSphereDataSource;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.swapper.OrchestrationCenterConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.swapper.OrchestrationCenterConfigurationYamlSwapper;
import org.apache.shardingsphere.spring.boot.datasource.DataSourceMapSetter;
import org.apache.shardingsphere.spring.boot.orchestration.common.OrchestrationSpringBootRootConfiguration;
import org.apache.shardingsphere.spring.boot.orchestration.rule.LocalRulesCondition;
......
......@@ -20,7 +20,7 @@ package org.apache.shardingsphere.spring.boot.orchestration.common;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.cluster.configuration.yaml.YamlClusterConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.Map;
......
......@@ -77,7 +77,7 @@
},
{
"name": "spring.shardingsphere.orchestration",
"type": "java.util.Map<java.lang.String,org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationCenterConfiguration>",
"type": "java.util.Map<java.lang.String,org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationCenterConfiguration>",
"sourceType": "org.apache.shardingsphere.spring.boot.orchestration.common.OrchestrationSpringBootRootConfiguration",
"description": "Customize ShardingSphere orchestration instance."
},
......
......@@ -21,7 +21,7 @@ import lombok.SneakyThrows;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
import org.apache.shardingsphere.driver.orchestration.internal.datasource.OrchestrationShardingSphereDataSource;
import org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration;
import org.apache.shardingsphere.spring.boot.orchestration.registry.TestOrchestrationRepository;
import org.apache.shardingsphere.spring.boot.orchestration.util.EmbedTestingServer;
import org.junit.BeforeClass;
......
......@@ -15,7 +15,7 @@
# limitations under the License.
#
dataSource: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration
dataSource: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource
props:
url: jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
......
......@@ -15,21 +15,21 @@
# limitations under the License.
#
ds: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration
ds: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource
props:
url: jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
maxTotal: 16
password: ''
username: sa
ds_0: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration
ds_0: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource
props:
url: jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
maxTotal: 16
password: ''
username: sa
ds_1: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration
ds_1: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource
props:
url: jdbc:h2:mem:ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
......
......@@ -34,7 +34,7 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-orchestration-repository-common</artifactId>
<artifactId>shardingsphere-orchestration-core-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
......
......@@ -23,7 +23,7 @@ import org.apache.shardingsphere.cluster.configuration.yaml.YamlClusterConfigura
import org.apache.shardingsphere.infra.auth.yaml.config.YamlAuthenticationConfiguration;
import org.apache.shardingsphere.infra.yaml.config.YamlConfiguration;
import org.apache.shardingsphere.metrics.configuration.yaml.YamlMetricsConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
import java.util.Properties;
......
......@@ -28,8 +28,8 @@ import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
import org.apache.shardingsphere.metrics.configuration.swapper.MetricsConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.facade.OrchestrationFacade;
import org.apache.shardingsphere.orchestration.repository.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.repository.common.yaml.swapper.OrchestrationConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlOrchestrationConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.swapper.OrchestrationConfigurationYamlSwapper;
import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
import org.apache.shardingsphere.proxy.config.ShardingConfiguration;
import org.apache.shardingsphere.proxy.config.converter.AbstractConfigurationConverter;
......
......@@ -27,7 +27,7 @@ import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.CharsetUtil;
import org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration;
import org.apache.shardingsphere.scaling.core.config.ScalingConfiguration;
import org.apache.shardingsphere.scaling.core.config.ScalingContext;
import org.apache.shardingsphere.scaling.core.config.ServerConfiguration;
......
......@@ -17,7 +17,7 @@
{
"ruleConfiguration": {
"sourceDatasource": "ds_0: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n username: root\n password: '123456'\n connectionTimeout: 30000\n idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly: false\n",
"sourceDatasource": "ds_0: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n username: root\n password: '123456'\n connectionTimeout: 30000\n idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly: false\n",
"sourceRule": "defaultDatabaseStrategy:\n standard:\n shardingAlgorithmName: inline\n shardingColumn: user_id\ntables:\n t1:\n actualDataNodes: ds_0.t1\n keyGenerateStrategy:\n column: order_id\n logicTable: t1\n tableStrategy:\n standard:\n shardingAlgorithmName: inline\n shardingColumn: order_id\n t2:\n actualDataNodes: ds_0.t2\n keyGenerateStrategy:\n column: order_item_id\n logicTable: t2\n tableStrategy:\n standard:\n shardingAlgorithmName: inline\n shardingColumn: order_id",
"destinationDataSources": {
"name": "dt_0",
......
......@@ -21,8 +21,8 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.orchestration.core.common.configuration.DataSourceConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration;
import org.apache.shardingsphere.orchestration.core.common.yaml.swapper.DataSourceConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.yaml.swapper.ShardingRuleConfigurationYamlSwapper;
......@@ -43,7 +43,7 @@ public final class ConfigurationYamlConverter {
* @param data data
* @return data source configurations
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
public static Map<String, DataSourceConfiguration> loadDataSourceConfigurations(final String data) {
Map<String, YamlDataSourceConfiguration> result = (Map) YamlEngine.unmarshal(data);
Preconditions.checkState(null != result && !result.isEmpty(), "No available data sources to load for orchestration.");
......
......@@ -17,7 +17,7 @@
{
"ruleConfiguration": {
"sourceDatasource": "ds_0: !!org.apache.shardingsphere.orchestration.core.common.configuration.YamlDataSourceConfiguration\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n username: root\n password: '123456'\n connectionTimeout: 30000\n idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly: false\n",
"sourceDatasource": "ds_0: !!org.apache.shardingsphere.orchestration.core.common.yaml.config.YamlDataSourceConfiguration\n dataSourceClassName: com.zaxxer.hikari.HikariDataSource\n props:\n jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false\n username: root\n password: '123456'\n connectionTimeout: 30000\n idleTimeout: 60000\n maxLifetime: 1800000\n maxPoolSize: 50\n minPoolSize: 1\n maintenanceIntervalMilliseconds: 30000\n readOnly: false\n",
"sourceRule": "defaultDatabaseStrategy:\n standard:\n shardingAlgorithmName: inline\n shardingColumn: user_id\ntables:\n t1:\n actualDataNodes: ds_0.t1\n keyGenerateStrategy:\n column: order_id\n logicTable: t1\n tableStrategy:\n standard:\n shardingAlgorithmName: inline\n shardingColumn: order_id\n t2:\n actualDataNodes: ds_0.t2\n keyGenerateStrategy:\n column: order_item_id\n logicTable: t2\n tableStrategy:\n standard:\n shardingAlgorithmName: inline\n shardingColumn: order_id",
"destinationDataSources": {
"name": "dt_0",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册