diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/StorageResourceCreator.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/StorageResourceCreator.java index fd8c98d429d81..70ed45e9df4ad 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/StorageResourceCreator.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/StorageResourceCreator.java @@ -113,8 +113,8 @@ public static StorageResource createStorageResourceWithoutDataSource(final Map getStorageNodeDataSourcePoolProperties(final Map storageUnitDataSourcePoolProps) { - Map result = new LinkedHashMap<>(); + public static Map getStorageNodeDataSourcePoolProperties(final Map storageUnitDataSourcePoolProps) { + Map result = new LinkedHashMap<>(); Collection storageNodes = new HashSet<>(); for (Entry entry : storageUnitDataSourcePoolProps.entrySet()) { Map standardProps = entry.getValue().getConnectionPropertySynonyms().getStandardProperties(); @@ -122,7 +122,7 @@ public static Map getStorageNodeDataSourcePool boolean isInstanceConnectionAvailable = new DatabaseTypeRegistry(DatabaseTypeFactory.get(url)).getDialectDatabaseMetaData().isInstanceConnectionAvailable(); StorageNode storageNode = new StorageNode(getStorageNodeName(entry.getKey(), url, standardProps.get("username").toString(), isInstanceConnectionAvailable)); if (storageNodes.add(storageNode)) { - result.put(storageNode.getName(), entry.getValue()); + result.put(storageNode, entry.getValue()); } } return result; diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java index 670f6af2caa86..709c63526a19f 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/NewResourceSwitchManager.java @@ -55,11 +55,11 @@ public SwitchingResource registerStorageUnit(final ResourceMetaData resourceMeta private StorageResource getRegisterNewStorageResource(final ResourceMetaData resourceMetaData, final StorageResource toBeCreatedStorageResource, final Map storageUnitDataSourcePoolProps) { - Map storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); + Map storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); Map storageNodes = new LinkedHashMap<>(toBeCreatedStorageResource.getDataSourceMap().size(), 1F); for (StorageNode each : toBeCreatedStorageResource.getDataSourceMap().keySet()) { if (!resourceMetaData.getDataSourceMap().containsKey(each)) { - storageNodes.put(each, DataSourcePoolCreator.create(storageNodeDataSourcePoolProps.get(each.getName()))); + storageNodes.put(each, DataSourcePoolCreator.create(storageNodeDataSourcePoolProps.get(each))); } } return new StorageResource(storageNodes, toBeCreatedStorageResource.getStorageUnitNodeMappers()); @@ -81,10 +81,10 @@ public SwitchingResource alterStorageUnit(final ResourceMetaData resourceMetaDat } private StorageResource getAlterNewStorageResource(final StorageResource toBeAlteredStorageResource, final Map storageUnitDataSourcePoolProps) { - Map storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); + Map storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); Map storageNodes = new LinkedHashMap<>(toBeAlteredStorageResource.getDataSourceMap().size(), 1F); for (StorageNode each : toBeAlteredStorageResource.getDataSourceMap().keySet()) { - storageNodes.put(each, DataSourcePoolCreator.create(storageNodeDataSourcePoolProps.get(each.getName()))); + storageNodes.put(each, DataSourcePoolCreator.create(storageNodeDataSourcePoolProps.get(each))); } return new StorageResource(storageNodes, toBeAlteredStorageResource.getStorageUnitNodeMappers()); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java index fc7310135292b..14bd869122293 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/switcher/ResourceSwitchManager.java @@ -94,15 +94,15 @@ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMet private StorageResource createNewStorageResource(final ResourceMetaData resourceMetaData, final StorageResource toBeChangedStorageResource, final Map storageUnitDataSourcePoolProps) { - Map storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); + Map storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps); Map storageNodes = getNewStorageNodes(resourceMetaData, toBeChangedStorageResource.getDataSourceMap(), storageNodeDataSourcePoolProps); Map storageUnitNodeMappers = getNewStorageUnitNodeMappers(resourceMetaData, toBeChangedStorageResource.getStorageUnitNodeMappers()); return new StorageResource(storageNodes, storageUnitNodeMappers); } - private Map getNewStorageNodes(final ResourceMetaData resourceMetaData, - final Map toBeChangedStorageNodes, final Map propsMap) { + private Map getNewStorageNodes(final ResourceMetaData resourceMetaData, final Map toBeChangedStorageNodes, + final Map propsMap) { Map result = new LinkedHashMap<>(resourceMetaData.getDataSourceMap()); result.keySet().removeAll(getToBeDeletedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodes.keySet()).keySet()); result.putAll(getChangedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodes, propsMap)); @@ -119,12 +119,12 @@ private Map getNewStorageUnitNodeMappers(final Re } private Map getChangedDataSources(final Map storageNodes, - final Map toBeChangedStorageNodes, final Map propsMap) { + final Map toBeChangedStorageNodes, final Map propsMap) { Collection toBeChangedDataSourceNames = toBeChangedStorageNodes.keySet().stream() - .filter(each -> isModifiedDataSource(storageNodes, each, propsMap.get(each.getName()))).collect(Collectors.toList()); + .filter(each -> isModifiedDataSource(storageNodes, each, propsMap.get(each))).collect(Collectors.toList()); Map result = new LinkedHashMap<>(toBeChangedStorageNodes.size(), 1F); for (StorageNode each : toBeChangedDataSourceNames) { - result.put(each, DataSourcePoolCreator.create(propsMap.get(each.getName()))); + result.put(each, DataSourcePoolCreator.create(propsMap.get(each))); } return result; } @@ -134,11 +134,11 @@ private boolean isModifiedDataSource(final Map original } private Map getToBeAddedDataSources(final Map storageNodes, final Map toBeChangedStorageNodes, - final Map propsMap) { + final Map propsMap) { Collection toBeAddedDataSourceNames = toBeChangedStorageNodes.keySet().stream().filter(each -> !storageNodes.containsKey(each)).collect(Collectors.toList()); Map result = new LinkedHashMap<>(); for (StorageNode each : toBeAddedDataSourceNames) { - result.put(each, DataSourcePoolCreator.create(propsMap.get(each.getName()))); + result.put(each, DataSourcePoolCreator.create(propsMap.get(each))); } return result; } @@ -165,10 +165,10 @@ private StorageResource getStaleDataSources(final ResourceMetaData resourceMetaD return new StorageResource(storageNodes, storageUnitNodeMappers); } - private Map getToBeChangedDataSources(final Map storageNodes, final Map propsMap) { + private Map getToBeChangedDataSources(final Map storageNodes, final Map propsMap) { Map result = new LinkedHashMap<>(storageNodes.size(), 1F); - for (Entry entry : propsMap.entrySet()) { - StorageNode storageNode = new StorageNode(entry.getKey()); + for (Entry entry : propsMap.entrySet()) { + StorageNode storageNode = entry.getKey(); if (isModifiedDataSource(storageNodes, storageNode, entry.getValue())) { result.put(storageNode, storageNodes.get(storageNode)); }