Skip to content

Commit

Permalink
Convert StorageResourceCreator.getStorageNodeDataSourcePoolProperties()
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 26, 2023
1 parent 95c8394 commit c6ddb26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ public static StorageResource createStorageResourceWithoutDataSource(final Map<S
* @param storageUnitDataSourcePoolProps storage unit grouped data source pool properties map
* @return storage node grouped data source pool properties map
*/
public static Map<String, DataSourcePoolProperties> getStorageNodeDataSourcePoolProperties(final Map<String, DataSourcePoolProperties> storageUnitDataSourcePoolProps) {
Map<String, DataSourcePoolProperties> result = new LinkedHashMap<>();
public static Map<StorageNode, DataSourcePoolProperties> getStorageNodeDataSourcePoolProperties(final Map<String, DataSourcePoolProperties> storageUnitDataSourcePoolProps) {
Map<StorageNode, DataSourcePoolProperties> result = new LinkedHashMap<>();
Collection<StorageNode> storageNodes = new HashSet<>();
for (Entry<String, DataSourcePoolProperties> entry : storageUnitDataSourcePoolProps.entrySet()) {
Map<String, Object> standardProps = entry.getValue().getConnectionPropertySynonyms().getStandardProperties();
String url = standardProps.get("url").toString();
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public SwitchingResource registerStorageUnit(final ResourceMetaData resourceMeta

private StorageResource getRegisterNewStorageResource(final ResourceMetaData resourceMetaData,
final StorageResource toBeCreatedStorageResource, final Map<String, DataSourcePoolProperties> storageUnitDataSourcePoolProps) {
Map<String, DataSourcePoolProperties> storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps);
Map<StorageNode, DataSourcePoolProperties> storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps);
Map<StorageNode, DataSource> 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());
Expand All @@ -81,10 +81,10 @@ public SwitchingResource alterStorageUnit(final ResourceMetaData resourceMetaDat
}

private StorageResource getAlterNewStorageResource(final StorageResource toBeAlteredStorageResource, final Map<String, DataSourcePoolProperties> storageUnitDataSourcePoolProps) {
Map<String, DataSourcePoolProperties> storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps);
Map<StorageNode, DataSourcePoolProperties> storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps);
Map<StorageNode, DataSource> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public SwitchingResource createByAlterDataSourcePoolProperties(final ResourceMet

private StorageResource createNewStorageResource(final ResourceMetaData resourceMetaData,
final StorageResource toBeChangedStorageResource, final Map<String, DataSourcePoolProperties> storageUnitDataSourcePoolProps) {
Map<String, DataSourcePoolProperties> storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps);
Map<StorageNode, DataSourcePoolProperties> storageNodeDataSourcePoolProps = StorageResourceCreator.getStorageNodeDataSourcePoolProperties(storageUnitDataSourcePoolProps);
Map<StorageNode, DataSource> storageNodes =
getNewStorageNodes(resourceMetaData, toBeChangedStorageResource.getDataSourceMap(), storageNodeDataSourcePoolProps);
Map<String, StorageUnitNodeMapper> storageUnitNodeMappers = getNewStorageUnitNodeMappers(resourceMetaData, toBeChangedStorageResource.getStorageUnitNodeMappers());
return new StorageResource(storageNodes, storageUnitNodeMappers);
}

private Map<StorageNode, DataSource> getNewStorageNodes(final ResourceMetaData resourceMetaData,
final Map<StorageNode, DataSource> toBeChangedStorageNodes, final Map<String, DataSourcePoolProperties> propsMap) {
private Map<StorageNode, DataSource> getNewStorageNodes(final ResourceMetaData resourceMetaData, final Map<StorageNode, DataSource> toBeChangedStorageNodes,
final Map<StorageNode, DataSourcePoolProperties> propsMap) {
Map<StorageNode, DataSource> result = new LinkedHashMap<>(resourceMetaData.getDataSourceMap());
result.keySet().removeAll(getToBeDeletedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodes.keySet()).keySet());
result.putAll(getChangedDataSources(resourceMetaData.getDataSourceMap(), toBeChangedStorageNodes, propsMap));
Expand All @@ -119,12 +119,12 @@ private Map<String, StorageUnitNodeMapper> getNewStorageUnitNodeMappers(final Re
}

private Map<StorageNode, DataSource> getChangedDataSources(final Map<StorageNode, DataSource> storageNodes,
final Map<StorageNode, DataSource> toBeChangedStorageNodes, final Map<String, DataSourcePoolProperties> propsMap) {
final Map<StorageNode, DataSource> toBeChangedStorageNodes, final Map<StorageNode, DataSourcePoolProperties> propsMap) {
Collection<StorageNode> 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<StorageNode, DataSource> 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;
}
Expand All @@ -134,11 +134,11 @@ private boolean isModifiedDataSource(final Map<StorageNode, DataSource> original
}

private Map<StorageNode, DataSource> getToBeAddedDataSources(final Map<StorageNode, DataSource> storageNodes, final Map<StorageNode, DataSource> toBeChangedStorageNodes,
final Map<String, DataSourcePoolProperties> propsMap) {
final Map<StorageNode, DataSourcePoolProperties> propsMap) {
Collection<StorageNode> toBeAddedDataSourceNames = toBeChangedStorageNodes.keySet().stream().filter(each -> !storageNodes.containsKey(each)).collect(Collectors.toList());
Map<StorageNode, DataSource> 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;
}
Expand All @@ -165,10 +165,10 @@ private StorageResource getStaleDataSources(final ResourceMetaData resourceMetaD
return new StorageResource(storageNodes, storageUnitNodeMappers);
}

private Map<StorageNode, DataSource> getToBeChangedDataSources(final Map<StorageNode, DataSource> storageNodes, final Map<String, DataSourcePoolProperties> propsMap) {
private Map<StorageNode, DataSource> getToBeChangedDataSources(final Map<StorageNode, DataSource> storageNodes, final Map<StorageNode, DataSourcePoolProperties> propsMap) {
Map<StorageNode, DataSource> result = new LinkedHashMap<>(storageNodes.size(), 1F);
for (Entry<String, DataSourcePoolProperties> entry : propsMap.entrySet()) {
StorageNode storageNode = new StorageNode(entry.getKey());
for (Entry<StorageNode, DataSourcePoolProperties> entry : propsMap.entrySet()) {
StorageNode storageNode = entry.getKey();
if (isModifiedDataSource(storageNodes, storageNode, entry.getValue())) {
result.put(storageNode, storageNodes.get(storageNode));
}
Expand Down

0 comments on commit c6ddb26

Please sign in to comment.