GutoVeronezi commented on code in PR #7895:
URL: https://github.com/apache/cloudstack/pull/7895#discussion_r1326734779


##########
framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java:
##########
@@ -1143,6 +1134,38 @@ public static void initDataSource(Properties dbProps) {
         }
     }
 
+    private static String getConnectionUri(Properties dbProps, String 
loadBalanceStrategy, String driver, boolean useSSL, String databaseName) {
+        String connectionUri;
+        String uri = dbProps.getProperty(String.format("db.%s.uri", 
databaseName));
+
+        if (StringUtils.isEmpty(uri)) {
+            String host = dbProps.getProperty(String.format("db.%s.host", 
databaseName));
+            int port = 
Integer.parseInt(dbProps.getProperty(String.format("db.%s.port", 
databaseName)));
+            String dbName = dbProps.getProperty(String.format("db.%s.name", 
databaseName));
+            boolean autoReconnect = 
Boolean.parseBoolean(dbProps.getProperty(String.format("db.%s.autoReconnect", 
databaseName)));
+            String url = dbProps.getProperty(String.format("db.%s.url.params", 
databaseName));
+
+            String replicas = null;
+            String dbHaParams = null;
+            if (s_dbHAEnabled) {
+                dbHaParams = getDBHAParams(databaseName, dbProps);
+                replicas = dbProps.getProperty(String.format("db.%s.replicas", 
databaseName));
+                s_logger.info(String.format("The replicas configured for %s 
data base are %s.", databaseName, replicas));
+            }
+
+            connectionUri = driver + "://" + host + (s_dbHAEnabled ? "," + 
replicas : "") + ":" + port + "/" + dbName +
+                    "?autoReconnect=" + autoReconnect + (url != null ? "&" + 
url : "") + (useSSL ? "&useSSL=true" : "") +
+                    (s_dbHAEnabled ? "&" + dbHaParams : "") + (s_dbHAEnabled ? 
"&loadBalanceStrategy=" + loadBalanceStrategy : "");
+        } else {
+            s_logger.warn(String.format("db.%s.uri was set, only using the 
following properties of db.properties: [maxActive, maxIdle, maxWait, username, 
password, driver, "

Review Comment:
   This information is incorrect; we have a bunch of other properties that 
still will be used. It would be clearer if we would inform the properties that 
will be ignored.



##########
framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java:
##########
@@ -1032,11 +1033,7 @@ public static void initDataSource(Properties dbProps) {
             final long cloudMaxWait = 
Long.parseLong(dbProps.getProperty("db.cloud.maxWait"));
             final String cloudUsername = 
dbProps.getProperty("db.cloud.username");
             final String cloudPassword = 
dbProps.getProperty("db.cloud.password");
-            final String cloudHost = dbProps.getProperty("db.cloud.host");
             final String cloudDriver = dbProps.getProperty("db.cloud.driver");

Review Comment:
   If we inform the full URI, we can retrieve the driver from it, making this 
property unnecessary in this scenario.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to