Skip to content

Commit

Permalink
Refactor ResourceSwitchManager
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojinchao95 committed Oct 16, 2023
1 parent b8427b8 commit 251d4e0
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ public final class ResourceSwitchManager {
* @return created switching resource
*/
public SwitchingResource create(final ResourceMetaData resourceMetaData, final Map<String, DataSourcePoolProperties> toBeChangedPropsMap) {
Map<String, DataSourcePoolProperties> mergedPropsMap = new LinkedHashMap<>(resourceMetaData.getStorageUnits().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
mergedPropsMap.putAll(toBeChangedPropsMap);
Map<String, DataSourcePoolProperties> mergedPropsMap = new LinkedHashMap<>(toBeChangedPropsMap.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, Entry::getValue, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
Map<String, StorageNode> toBeChangedStorageUnitNodeMap = StorageUnitNodeMapCreator.create(toBeChangedPropsMap);
Map<StorageNode, DataSourcePoolProperties> dataSourcePoolPropsMap = StorageNodeAggregator.aggregateDataSourcePoolProperties(toBeChangedPropsMap);
Map<StorageNode, DataSource> newDataSources = createNewDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, dataSourcePoolPropsMap);
Expand Down Expand Up @@ -82,18 +81,16 @@ public SwitchingResource createByDropResource(final ResourceMetaData resourceMet
* @return created switching resource
*/
public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMetaData resourceMetaData, final Map<String, DataSourcePoolProperties> toBeChangedPropsMap) {
Map<String, DataSourcePoolProperties> mergedDataSourcePoolPropsMap = new LinkedHashMap<>(resourceMetaData.getStorageUnits().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSourcePoolProperties(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
mergedDataSourcePoolPropsMap.keySet().removeIf(each -> !toBeChangedPropsMap.containsKey(each));
mergedDataSourcePoolPropsMap.putAll(toBeChangedPropsMap);
Map<String, DataSourcePoolProperties> mergedPropsMap = new LinkedHashMap<>(toBeChangedPropsMap.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, Entry::getValue, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
Map<String, StorageNode> toBeChangedStorageUnitNodeMap = StorageUnitNodeMapCreator.create(toBeChangedPropsMap);
Map<StorageNode, DataSource> staleStorageDataSources = getStaleDataSources(resourceMetaData, toBeChangedPropsMap);
staleStorageDataSources.putAll(getToBeDeletedDataSources(resourceMetaData.getDataSources(), toBeChangedStorageUnitNodeMap.values()));
Collection<String> staleStorageUnitNames = getStaleStorageUnitNames(resourceMetaData, toBeChangedStorageUnitNodeMap);
staleStorageUnitNames.addAll(getToBeDeletedStorageUnitNames(resourceMetaData.getStorageUnits(), toBeChangedStorageUnitNodeMap.keySet()));
Map<StorageNode, DataSourcePoolProperties> dataSourcePoolPropsMap = StorageNodeAggregator.aggregateDataSourcePoolProperties(toBeChangedPropsMap);
return new SwitchingResource(
createNewDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, dataSourcePoolPropsMap), staleStorageDataSources, staleStorageUnitNames, mergedDataSourcePoolPropsMap);
createNewDataSources(resourceMetaData, toBeChangedStorageUnitNodeMap, dataSourcePoolPropsMap), staleStorageDataSources, staleStorageUnitNames, mergedPropsMap);
}

private Map<StorageNode, DataSource> createNewDataSources(final ResourceMetaData resourceMetaData, final Map<String, StorageNode> toBeChangedStorageUnitNodeMap,
Expand Down

0 comments on commit 251d4e0

Please sign in to comment.