Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor StorageNodeUtils #28604

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator;
import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import org.apache.shardingsphere.infra.metadata.database.resource.StorageResource;
import org.apache.shardingsphere.infra.metadata.database.resource.StorageResourceUtils;
import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeUtils;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapperUtils;

import javax.sql.DataSource;
Expand All @@ -49,7 +49,7 @@ public final class DataSourceProvidedDatabaseConfiguration implements DatabaseCo

public DataSourceProvidedDatabaseConfiguration(final Map<String, DataSource> dataSources, final Collection<RuleConfiguration> ruleConfigs) {
this.ruleConfigurations = ruleConfigs;
storageResource = new StorageResource(StorageResourceUtils.getStorageNodeDataSources(dataSources), StorageUnitNodeMapperUtils.fromDataSources(dataSources));
storageResource = new StorageResource(StorageNodeUtils.getStorageNodeDataSources(dataSources), StorageUnitNodeMapperUtils.fromDataSources(dataSources));
dataSourcePoolPropertiesMap = createDataSourcePoolPropertiesMap(dataSources);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.shardingsphere.infra.datasource.pool.props.creator.DataSourcePoolPropertiesCreator;
import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeUtils;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitNodeMapper;
Expand Down Expand Up @@ -51,7 +52,7 @@ public ResourceMetaData(final Map<String, DataSource> dataSources) {
}

public ResourceMetaData(final String databaseName, final Map<String, DataSource> dataSources) {
dataSourceMap = StorageResourceUtils.getStorageNodeDataSources(dataSources);
dataSourceMap = StorageNodeUtils.getStorageNodeDataSources(dataSources);
storageUnitMetaData = new StorageUnitMetaData(databaseName, dataSourceMap, dataSources.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)),
StorageUnitNodeMapperUtils.fromDataSources(dataSources));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
* limitations under the License.
*/

package org.apache.shardingsphere.infra.metadata.database.resource;
package org.apache.shardingsphere.infra.metadata.database.resource.node;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;

import javax.sql.DataSource;
import java.util.LinkedHashMap;
Expand All @@ -28,10 +27,10 @@
import java.util.stream.Collectors;

/**
* Storage resource utility class.
* Storage node utility class.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class StorageResourceUtils {
public final class StorageNodeUtils {

/**
* Get storage node data sources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
import org.apache.shardingsphere.infra.metadata.database.resource.StorageResourceUtils;
import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNodeUtils;
import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnitMetaData;
Expand Down Expand Up @@ -222,7 +222,7 @@ private void assertAlteredDataSource(final MockedDataSource actual) {
void assertAlterRuleConfiguration() {
ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS);
Map<String, DataSource> dataSources = Collections.singletonMap("foo_ds", new MockedDataSource());
when(resourceMetaData.getDataSourceMap()).thenReturn(StorageResourceUtils.getStorageNodeDataSources(dataSources));
when(resourceMetaData.getDataSourceMap()).thenReturn(StorageNodeUtils.getStorageNodeDataSources(dataSources));
StorageUnitMetaData storageUnitMetaData = mock(StorageUnitMetaData.class);
when(resourceMetaData.getStorageUnitMetaData()).thenReturn(storageUnitMetaData);
when(storageUnitMetaData.getStorageUnits()).thenReturn(Collections.emptyMap());
Expand Down Expand Up @@ -254,7 +254,7 @@ private ResourceMetaData createOriginalResource() {
originalDataSources.put("ds_1", new MockedDataSource());
originalDataSources.put("ds_2", new MockedDataSource());
when(result.getStorageUnitMetaData().getDataSources()).thenReturn(originalDataSources);
Map<StorageNode, DataSource> storageNodeDataSourceMap = StorageResourceUtils.getStorageNodeDataSources(originalDataSources);
Map<StorageNode, DataSource> storageNodeDataSourceMap = StorageNodeUtils.getStorageNodeDataSources(originalDataSources);
Map<String, StorageUnit> storageUnits = new LinkedHashMap<>(2, 1F);
Map<String, StorageUnitNodeMapper> storageUnitNodeMappers = StorageUnitNodeMapperUtils.fromDataSources(originalDataSources);
for (Entry<String, StorageUnitNodeMapper> entry : storageUnitNodeMappers.entrySet()) {
Expand Down