未验证 提交 93123ece 编写于 作者: 流浪诗人 提交者: GitHub

orchestration mode code optimization . (#4825)

* orchestration mode code optimization .

* orchestration mode code optimization .

* orchestration mode code optimization .

* orchestration mode code optimization .

* charset ues guava .

* four blank line

* four blank line

* four blank line.

* four blank line.

* orchestration mode code optimization .
上级 43df98f9
......@@ -228,7 +228,7 @@ public final class CuratorZookeeperCenterRepository implements ConfigCenterRepos
}
DataChangedEvent.ChangedType changedType = getChangedType(event);
if (DataChangedEvent.ChangedType.IGNORED != changedType) {
dataChangedEventListener.onChange(new DataChangedEvent(data.getPath(), null == data.getData() ? null : new String(data.getData(), "UTF-8"), changedType));
dataChangedEventListener.onChange(new DataChangedEvent(data.getPath(), null == data.getData() ? null : new String(data.getData(), Charsets.UTF_8), changedType));
}
});
}
......
......@@ -19,6 +19,7 @@ package org.apache.shardingsphere.orchestration.core.common;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.orchestration.center.exception.OrchestrationException;
import java.util.Arrays;
......@@ -41,6 +42,8 @@ public enum CenterType {
* @return OrchestrationType enum, return {@code null} if not found
*/
public static CenterType findByValue(final String value) {
return Arrays.stream(CenterType.values()).filter(each -> each.getValue().equals(value)).findFirst().get();
return Arrays.stream(CenterType.values())
.filter(each -> each.getValue().equals(value)).findFirst()
.orElseThrow(() -> new OrchestrationException("now only support :{},{}", CenterType.CONFIG_CENTER.getValue(), CenterType.REGISTRY_CENTER.getValue()));
}
}
......@@ -89,14 +89,14 @@ public final class ConfigCenter {
if (isOverwrite || !hasDataSourceConfiguration(shardingSchemaName)) {
Preconditions.checkState(null != dataSourceConfigurations && !dataSourceConfigurations.isEmpty(), "No available data source in `%s` for orchestration.", shardingSchemaName);
Map<String, YamlDataSourceConfiguration> yamlDataSourceConfigurations = dataSourceConfigurations.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(), e -> new DataSourceConfigurationYamlSwapper().swap(e.getValue())));
.collect(Collectors.toMap(Map.Entry::getKey, e -> new DataSourceConfigurationYamlSwapper().swap(e.getValue())));
repository.persist(node.getDataSourcePath(shardingSchemaName), YamlEngine.marshal(yamlDataSourceConfigurations));
}
}
/**
* Judge whether schema has data source configuration.
*
*
* @param shardingSchemaName shading schema name
* @return has data source configuration or not
*/
......@@ -239,7 +239,7 @@ public final class ConfigCenter {
public Map<String, DataSourceConfiguration> loadDataSourceConfigurations(final String shardingSchemaName) {
Map<String, YamlDataSourceConfiguration> result = (Map) YamlEngine.unmarshal(repository.get(node.getDataSourcePath(shardingSchemaName)));
Preconditions.checkState(null != result && !result.isEmpty(), "No available data sources to load for orchestration.");
return result.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> new DataSourceConfigurationYamlSwapper().swap(e.getValue())));
return result.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new DataSourceConfigurationYamlSwapper().swap(e.getValue())));
}
/**
......
......@@ -21,12 +21,12 @@ import org.apache.shardingsphere.core.yaml.config.common.YamlAuthenticationConfi
import org.apache.shardingsphere.core.yaml.swapper.AuthenticationYamlSwapper;
import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
import org.apache.shardingsphere.orchestration.center.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.core.configcenter.ConfigCenterNode;
import org.apache.shardingsphere.orchestration.core.common.event.AuthenticationChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.listener.PostShardingConfigCenterEventListener;
import org.apache.shardingsphere.orchestration.core.configcenter.ConfigCenterNode;
import org.apache.shardingsphere.underlying.common.yaml.engine.YamlEngine;
import java.util.Arrays;
import java.util.Collections;
/**
* Authentication changed listener.
......@@ -34,7 +34,7 @@ import java.util.Arrays;
public final class AuthenticationChangedListener extends PostShardingConfigCenterEventListener {
public AuthenticationChangedListener(final String name, final ConfigCenterRepository configCenterRepository) {
super(configCenterRepository, Arrays.asList(new ConfigCenterNode(name).getAuthenticationPath()));
super(configCenterRepository, Collections.singletonList(new ConfigCenterNode(name).getAuthenticationPath()));
}
@Override
......
......@@ -19,12 +19,12 @@ package org.apache.shardingsphere.orchestration.core.configcenter.listener;
import org.apache.shardingsphere.orchestration.center.ConfigCenterRepository;
import org.apache.shardingsphere.orchestration.center.listener.DataChangedEvent;
import org.apache.shardingsphere.orchestration.core.configcenter.ConfigCenterNode;
import org.apache.shardingsphere.orchestration.core.common.event.PropertiesChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.listener.PostShardingConfigCenterEventListener;
import org.apache.shardingsphere.orchestration.core.configcenter.ConfigCenterNode;
import org.apache.shardingsphere.underlying.common.yaml.engine.YamlEngine;
import java.util.Arrays;
import java.util.Collections;
/**
* Properties changed listener.
......@@ -32,7 +32,7 @@ import java.util.Arrays;
public final class PropertiesChangedListener extends PostShardingConfigCenterEventListener {
public PropertiesChangedListener(final String name, final ConfigCenterRepository configCenterRepository) {
super(configCenterRepository, Arrays.asList(new ConfigCenterNode(name).getPropsPath()));
super(configCenterRepository, Collections.singletonList(new ConfigCenterNode(name).getPropsPath()));
}
@Override
......
......@@ -120,7 +120,7 @@ public final class SchemaChangedListener extends PostShardingConfigCenterEventLi
Map<String, YamlDataSourceConfiguration> dataSourceConfigurations = (Map) YamlEngine.unmarshal(event.getValue());
Preconditions.checkState(null != dataSourceConfigurations && !dataSourceConfigurations.isEmpty(), "No available data sources to load for orchestration.");
return new DataSourceChangedEvent(shardingSchemaName, dataSourceConfigurations.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(), e -> new DataSourceConfigurationYamlSwapper().swap(e.getValue()))));
.collect(Collectors.toMap(Map.Entry::getKey, e -> new DataSourceConfigurationYamlSwapper().swap(e.getValue()))));
}
private ShardingOrchestrationEvent createRuleChangedEvent(final String shardingSchemaName, final DataChangedEvent event) {
......
......@@ -60,6 +60,6 @@ public final class OrchestrationShardingSchemaGroup {
* @return data source names
*/
public Collection<String> getDataSourceNames(final String shardingSchemaName) {
return schemaGroup.containsKey(shardingSchemaName) ? schemaGroup.get(shardingSchemaName) : Collections.emptyList();
return schemaGroup.getOrDefault(shardingSchemaName, Collections.emptyList());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册