diff --git a/etc/storm.properties.template b/etc/storm.properties.template index 92ff2293..43bde697 100644 --- a/etc/storm.properties.template +++ b/etc/storm.properties.template @@ -11,21 +11,11 @@ ############################ ### SERVICE PARAMETERS ### ############################ -## -## NOTE: -## The SERVICE PARAMETERS are managed also by YAIM. -## So, if you install and configure the service with YAIM, please -## remember that the parameters tagged as YAIM will be overwrite at every -## reconfiguration done with YAIM, so if you want change some parameters -## you should use the YAIM configuration files: -## /services/ig-se_storm_backend (or equivalent) -## # ============================ # StoRM Service DNS # ============================ # hostname with which the service is published -# storm.service.FE-public.hostname = @@ -33,7 +23,6 @@ storm.service.FE-public.hostname = # Front End service port # ============================ # The Front End binding port -# storm.service.port = 8444 # ============================ @@ -44,7 +33,6 @@ storm.service.port = 8444 # These entries are used to check the SURL validity. # storm.service.SURL.endpoint = srm://:/ # Example: Example: srm://storm.cnaf.infn.it:8444/srm/managerv2 -# storm.service.SURL.endpoint = # ============================ @@ -55,7 +43,6 @@ storm.service.SURL.endpoint = # These entries are used to check the SURL validity. # storm.service.SURL.default-ports = # Example: 8444 -# storm.service.SURL.default-ports = # ============================ @@ -63,7 +50,6 @@ storm.service.SURL.default-ports = # ============================ # # Parameters to connect to the DB used as channel for the requests. -# storm.service.request-db.host = storm.service.request-db.username = storm.service.request-db.passwd = @@ -71,11 +57,6 @@ storm.service.request-db.passwd = ############################################# ############ PROFILE PARAMETERS ############ ############################################# -## -## NOTE: -## The PROFILE PARAMETERS are not managed by YAIM in any case, -## so any change must be managed by directly editing this file. -## # ============================ # StoRM Service Generic Behavior @@ -119,17 +100,10 @@ default.storagetype = P ############################################# ############ TUNING PARAMETERS ############# ############################################# -## -## NOTE: -## The TUNING PARAMETERS are not managed by YAIM in any case, -## so any change must be managed by directly editing this file. -## - # ============================ # BE-private RDBMS # ============================ -persistence.internal-db.connection-pool = true persistence.internal-db.connection-pool.maxActive = 50 persistence.internal-db.connection-pool.maxWait = 50 @@ -207,7 +181,6 @@ tape.recalltable.service.param.takeover=first # ============================ # srmCopy parameters # ============================ -proxy.home=/opt/storm/backend/tmp asynch.srmclient.retrytime=60 asynch.srmclient.timeout=180 asynch.srmclient.sleeptime=5 @@ -292,4 +265,3 @@ storm.service.du.parallelTasks=false storm.service.du.delaySecs=60 # Interval of execution of the du in seconds. Default: 86400s (24h) storm.service.du.periodSecs=86400 -ß \ No newline at end of file diff --git a/etc/systemd/storm-backend-server.service b/etc/systemd/storm-backend-server.service index bd8ab36e..1d7484d6 100644 --- a/etc/systemd/storm-backend-server.service +++ b/etc/systemd/storm-backend-server.service @@ -1,5 +1,6 @@ [Unit] Description=StoRM Backend service +After=mariadb.service [Service] WorkingDirectory=/etc/storm/backend-server diff --git a/pom.xml b/pom.xml index 9e111d92..9bf1ba0e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ StoRM Backend server org.italiangrid.storm storm-backend-server - 1.12.0 + 1.11.21 @@ -39,7 +39,7 @@ 18.0 3.1.0 - 2.11.0 + 2.12.1 1.10.19 1.3 diff --git a/src/main/java/it/grid/storm/catalogs/BoLChunkDAO.java b/src/main/java/it/grid/storm/catalogs/BoLChunkDAO.java index bd19757f..660340b6 100644 --- a/src/main/java/it/grid/storm/catalogs/BoLChunkDAO.java +++ b/src/main/java/it/grid/storm/catalogs/BoLChunkDAO.java @@ -69,7 +69,7 @@ public class BoLChunkDAO { /** String with the name of the class for the DB driver */ private final String driver = Configuration.getInstance().getDBDriver(); /** String referring to the URL of the DB */ - private final String url = Configuration.getInstance().getDBURL(); + private final String url = Configuration.getInstance().getStormDbURL(); /** String with the password for the DB */ private final String password = Configuration.getInstance().getDBPassword(); /** String with the name for the DB */ diff --git a/src/main/java/it/grid/storm/catalogs/CopyChunkDAO.java b/src/main/java/it/grid/storm/catalogs/CopyChunkDAO.java index 4e55e544..102af519 100644 --- a/src/main/java/it/grid/storm/catalogs/CopyChunkDAO.java +++ b/src/main/java/it/grid/storm/catalogs/CopyChunkDAO.java @@ -56,7 +56,7 @@ public class CopyChunkDAO { /* String with the name of the class for the DB driver */ private final String driver = Configuration.getInstance().getDBDriver(); /* String referring to the URL of the DB */ - private final String url = Configuration.getInstance().getDBURL(); + private final String url = Configuration.getInstance().getStormDbURL(); /* String with the password for the DB */ private final String password = Configuration.getInstance().getDBPassword(); /* String with the name for the DB */ diff --git a/src/main/java/it/grid/storm/catalogs/PtGChunkDAO.java b/src/main/java/it/grid/storm/catalogs/PtGChunkDAO.java index 393c1f62..2db12ab2 100644 --- a/src/main/java/it/grid/storm/catalogs/PtGChunkDAO.java +++ b/src/main/java/it/grid/storm/catalogs/PtGChunkDAO.java @@ -71,7 +71,7 @@ public class PtGChunkDAO { /** String with the name of the class for the DB driver */ private final String driver = Configuration.getInstance().getDBDriver(); /** String referring to the URL of the DB */ - private final String url = Configuration.getInstance().getDBURL(); + private final String url = Configuration.getInstance().getStormDbURL(); /** String with the password for the DB */ private final String password = Configuration.getInstance().getDBPassword(); /** String with the name for the DB */ diff --git a/src/main/java/it/grid/storm/catalogs/PtPChunkDAO.java b/src/main/java/it/grid/storm/catalogs/PtPChunkDAO.java index b6d89c3c..7d9c69fc 100644 --- a/src/main/java/it/grid/storm/catalogs/PtPChunkDAO.java +++ b/src/main/java/it/grid/storm/catalogs/PtPChunkDAO.java @@ -73,7 +73,7 @@ public class PtPChunkDAO { /* String with the name of the class for the DB driver */ private final String driver = Configuration.getInstance().getDBDriver(); /* String referring to the URL of the DB */ - private final String url = Configuration.getInstance().getDBURL(); + private final String url = Configuration.getInstance().getStormDbURL(); /* String with the password for the DB */ private final String password = Configuration.getInstance().getDBPassword(); /* String with the name for the DB */ diff --git a/src/main/java/it/grid/storm/catalogs/RequestSummaryDAO.java b/src/main/java/it/grid/storm/catalogs/RequestSummaryDAO.java index 1680e435..3b55f7b5 100644 --- a/src/main/java/it/grid/storm/catalogs/RequestSummaryDAO.java +++ b/src/main/java/it/grid/storm/catalogs/RequestSummaryDAO.java @@ -57,7 +57,7 @@ public class RequestSummaryDAO { /** String with the name of the class for the DB driver */ private final String driver = Configuration.getInstance().getDBDriver(); /** String referring to the URL of the DB */ - private final String url = Configuration.getInstance().getDBURL(); + private final String url = Configuration.getInstance().getStormDbURL(); /** String with the password for the DB */ private final String password = Configuration.getInstance().getDBPassword(); /** String with the name for the DB */ diff --git a/src/main/java/it/grid/storm/catalogs/StoRMDataSource.java b/src/main/java/it/grid/storm/catalogs/StoRMDataSource.java index 6513e67e..1db3057f 100644 --- a/src/main/java/it/grid/storm/catalogs/StoRMDataSource.java +++ b/src/main/java/it/grid/storm/catalogs/StoRMDataSource.java @@ -169,7 +169,7 @@ public static synchronized void init(){ Configuration conf = Configuration.getInstance(); instance = new StoRMDataSource.Builder() .driver(conf.getDBDriver()) - .url(conf.getDBURL()) + .url(conf.getStormDbURL()) .username(conf.getDBUserName()) .password(conf.getDBPassword()) .build(); diff --git a/src/main/java/it/grid/storm/catalogs/VolatileAndJiTDAO.java b/src/main/java/it/grid/storm/catalogs/VolatileAndJiTDAO.java index 8a0c596f..80685130 100644 --- a/src/main/java/it/grid/storm/catalogs/VolatileAndJiTDAO.java +++ b/src/main/java/it/grid/storm/catalogs/VolatileAndJiTDAO.java @@ -54,7 +54,7 @@ public class VolatileAndJiTDAO { private final String driver = Configuration.getInstance().getDBDriver(); // The URL of the DB - private final String url = Configuration.getInstance().getDBURL(); + private final String url = Configuration.getInstance().getStormDbURL(); // The password for the DB private final String password = Configuration.getInstance().getDBPassword(); diff --git a/src/main/java/it/grid/storm/config/Configuration.java b/src/main/java/it/grid/storm/config/Configuration.java index e325437f..678f1cc9 100644 --- a/src/main/java/it/grid/storm/config/Configuration.java +++ b/src/main/java/it/grid/storm/config/Configuration.java @@ -32,8 +32,6 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.lang.ArrayUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; @@ -56,8 +54,6 @@ public class Configuration { "/etc/storm/backend-server/storm.properties"; public static final int DEFAULT_STORM_CONFIG_REFRESH_RATE = 0; - private static final Logger log = LoggerFactory.getLogger(Configuration.class); - private final ConfigReader cr; private static Configuration instance; @@ -72,10 +68,8 @@ public class Configuration { private static final String SERVICE_HOSTNAME_KEY = "storm.service.FE-public.hostname"; private static final String SERVICE_PORT_KEY = "storm.service.port"; private static final String LIST_OF_MACHINE_IPS_KEY = "storm.service.FE-list.IPs"; - private static final String DB_DRIVER_KEY = "storm.service.request-db.dbms-vendor"; - private static final String DB_URL_1KEY = "storm.service.request-db.protocol"; - private static final String DB_URL_2KEY = "storm.service.request-db.host"; - private static final String DB_URL_3KEY = "storm.service.request-db.db-name"; + private static final String DB_URL_HOSTNAME = "storm.service.request-db.host"; + private static final String DB_URL_PROPERTIES = "storm.service.request-db.properties"; private static final String DB_USER_NAME_KEY = "storm.service.request-db.username"; private static final String DB_PASSWORD_KEY = "storm.service.request-db.passwd"; private static final String DB_RECONNECT_PERIOD_KEY = "asynch.db.ReconnectPeriod"; @@ -95,16 +89,6 @@ public class Configuration { private static final String XMLRPC_MAX_QUEUE_SIZE_KEY = "synchcall.xmlrpc.max_queue_size"; private static final String LIST_OF_DEFAULT_SPACE_TOKEN_KEY = "storm.service.defaultSpaceTokens"; private static final String COMMAND_SERVER_BINDING_PORT_KEY = "storm.commandserver.port"; - private static final String BE_PERSISTENCE_DB_VENDOR_KEY = "persistence.internal-db.dbms-vendor"; - private static final String BE_PERSISTENCE_DBMS_URL_1KEY = "persistence.internal-db.host"; - private static final String BE_PERSISTENCE_DBMS_URL_2KEY = "" + DB_URL_2KEY; - private static final String BE_PERSISTENCE_DB_NAME_KEY = "persistence.internal-db.db-name"; - private static final String BE_PERSISTENCEDB_USER_NAME_1KEY = "persistence.internal-db.username"; - private static final String BE_PERSISTENCEDB_USER_NAME_2KEY = "" + DB_USER_NAME_KEY; - private static final String BE_PERSISTENCE_DB_PASSWORD_1KEY = "persistence.internal-db.passwd"; - private static final String BE_PERSISTENCE_DB_PASSWORD_2KEY = "" + DB_PASSWORD_KEY; - private static final String BE_PERSISTENCE_POOL_DB_KEY = - "persistence.internal-db.connection-pool"; private static final String BE_PERSISTENCE_POOL_DB_MAX_ACTIVE_KEY = "persistence.internal-db.connection-pool.maxActive"; private static final String BE_PERSISTENCE_POOL_DB_MAX_WAIT_KEY = @@ -322,58 +306,21 @@ public List getListOfMachineIPs() { */ public String getDBDriver() { - if (!cr.getConfiguration().containsKey(DB_DRIVER_KEY)) { - return "com.mysql.cj.jdbc.Driver"; - } - String vendor = cr.getConfiguration().getString(DB_DRIVER_KEY); - String driver = ""; - if ("mysql".equalsIgnoreCase(vendor)) { - driver = "com.mysql.cj.jdbc.Driver"; - } else { - log.error("CONFIG ERROR 'RDBMS Vendor ('{}') unknown.'", vendor); - } - return driver; + return "com.mysql.cj.jdbc.Driver"; } /** * Method used by all DAO Objects to get DB URL. If no value is found in the configuration medium, - * then the default value is returned instead. key1="asynch.picker.db.protocol"; default - * value="jdbc:mysql://"; key2="asynch.picker.db.host"; default value="localhost"; - * key3="asynch.picker.db.name"; default value="storm_db"; The returned value is made up of the - * above default values and whatever is read from the configuration medium, combined in the - * following way: protocol + host + "/" + name - */ - public String getDBURL() { - - String prefix = ""; - String host = ""; - String name = ""; - // get prefix... - if (!cr.getConfiguration().containsKey(DB_URL_1KEY)) { - // use default - prefix = "jdbc:mysql://"; - } else { - // load from external source - prefix = cr.getConfiguration().getString(DB_URL_1KEY); - } - // get host... - if (!cr.getConfiguration().containsKey(DB_URL_2KEY)) { - // use default - host = "localhost"; - } else { - // load from external source - host = cr.getConfiguration().getString(DB_URL_2KEY); - } - // get db name... - if (!cr.getConfiguration().containsKey(DB_URL_3KEY)) { - // use default - name = "storm_db"; - } else { - // load from external source - name = cr.getConfiguration().getString(DB_URL_3KEY); + * then the default value is returned instead. + */ + public String getStormDbURL() { + + String host = getDBHostname(); + String properties = getDBProperties(); + if (properties.isEmpty()) { + return "jdbc:mysql://" + host + "/storm_db"; } - // return value... - return prefix + host + "/" + name; + return "jdbc:mysql://" + host + "/storm_db?" + properties; } /** @@ -388,7 +335,7 @@ public String getDBUserName() { /** * Method used by all DAO Objects to get the DB password. If no value is found in the - * configuration medium, then the default value is returned instead. Deafult value = "storm"; key + * configuration medium, then the default value is returned instead. Default value = "storm"; key * searched in medium = "asynch.picker.db.passwd". */ public String getDBPassword() { @@ -396,10 +343,20 @@ public String getDBPassword() { return cr.getConfiguration().getString(DB_PASSWORD_KEY, "storm"); } + public String getDBHostname() { + + return cr.getConfiguration().getString(DB_URL_HOSTNAME, "localhost"); + } + /* * END definition of MANDATORY PROPERTIES */ + public String getDBProperties() { + + return cr.getConfiguration().getString(DB_URL_PROPERTIES, "serverTimezone=UTC&autoReconnect=true"); + } + /** * Method used by all DAOs to establish the reconnection period in _seconds_: after such period * the DB connection will be closed and re-opened. Beware that after such time expires, the @@ -586,89 +543,6 @@ public int getCommandServerBindingPort() { return cr.getConfiguration().getInt(COMMAND_SERVER_BINDING_PORT_KEY, 4444); } - /** - * Method used in Persistence Component It returns the DB vendor name. If no value is found in the - * configuration medium, then the default value is returned instead. key="persistence.db.vendor"; - * default value="mysql"; - */ - public String getBEPersistenceDBVendor() { - - return cr.getConfiguration().getString(BE_PERSISTENCE_DB_VENDOR_KEY, "mysql"); - } - - /** - * Method used in Persistence Component: it returns the host where the DB resides. If no value is - * found in the configuration medium, then the default value is returned instead. - * key="persistence.db.host"; default value="localhost"; - */ - public String getBEPersistenceDBMSUrl() { - - if (cr.getConfiguration().containsKey(BE_PERSISTENCE_DBMS_URL_1KEY)) { - return cr.getConfiguration().getString(BE_PERSISTENCE_DBMS_URL_1KEY); - } - - if (cr.getConfiguration().containsKey(BE_PERSISTENCE_DBMS_URL_2KEY)) { - return cr.getConfiguration().getString(BE_PERSISTENCE_DBMS_URL_2KEY); - } - return "localhost"; - } - - /** - * Method used in Persistence Component it returns the name of the DB to use. If no value is found - * in the configuration medium, then the default value is returned instead. - * key="persistence.db.name"; default value="storm_be_ISAM"; - */ - public String getBEPersistenceDBName() { - - return cr.getConfiguration().getString(BE_PERSISTENCE_DB_NAME_KEY, "storm_be_ISAM"); - } - - /** - * Method used in Persistence Component it returns the name of the DB user that must be used. If - * no value is found in the configuration medium, then the default value is returned instead. - * key="persistence.db.username"; default value="storm"; - */ - public String getBEPersistenceDBUserName() { - - if (cr.getConfiguration().containsKey(BE_PERSISTENCEDB_USER_NAME_1KEY)) { - return cr.getConfiguration().getString(BE_PERSISTENCEDB_USER_NAME_1KEY); - } - - if (cr.getConfiguration().containsKey(BE_PERSISTENCEDB_USER_NAME_2KEY)) { - return cr.getConfiguration().getString(BE_PERSISTENCEDB_USER_NAME_2KEY); - } - - return "storm"; - } - - /** - * Method used in Persistence Component it returns the password for the DB user that must be used. - * If no value is found in the configuration medium, then the default value is returned instead. - * key="persistence.db.passwd"; default value="storm"; - */ - public String getBEPersistenceDBPassword() { - - if (cr.getConfiguration().containsKey(BE_PERSISTENCE_DB_PASSWORD_1KEY)) { - return cr.getConfiguration().getString(BE_PERSISTENCE_DB_PASSWORD_1KEY); - } - - if (cr.getConfiguration().containsKey(BE_PERSISTENCE_DB_PASSWORD_2KEY)) { - return cr.getConfiguration().getString(BE_PERSISTENCE_DB_PASSWORD_2KEY); - } - - return "storm"; - } - - /** - * Method used in Persistence Component it returns a boolean indicating whether to use connection - * pooling or not. If no value is found in the configuration medium, then the default value is - * returned instead. key="persistence.db.pool"; default value=false; - */ - public boolean getBEPersistencePoolDB() { - - return cr.getConfiguration().getBoolean(BE_PERSISTENCE_POOL_DB_KEY, false); - } - /** * Method used in Persistence Component it returns an int indicating the maximum number of active * connections in the connection pool. It is the maximum number of active connections that can be diff --git a/src/main/java/it/grid/storm/persistence/MySqlDAOFactory.java b/src/main/java/it/grid/storm/persistence/MySqlDAOFactory.java index d2d366b8..bf3de4ff 100644 --- a/src/main/java/it/grid/storm/persistence/MySqlDAOFactory.java +++ b/src/main/java/it/grid/storm/persistence/MySqlDAOFactory.java @@ -17,7 +17,9 @@ package it.grid.storm.persistence; -import it.grid.storm.config.Configuration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import it.grid.storm.persistence.dao.PtGChunkDAO; import it.grid.storm.persistence.dao.PtPChunkDAO; import it.grid.storm.persistence.dao.RequestSummaryDAO; @@ -25,15 +27,8 @@ import it.grid.storm.persistence.dao.StorageSpaceDAO; import it.grid.storm.persistence.dao.TapeRecallDAO; import it.grid.storm.persistence.exceptions.DataAccessException; -import it.grid.storm.persistence.exceptions.PersistenceException; import it.grid.storm.persistence.impl.mysql.StorageSpaceDAOMySql; import it.grid.storm.persistence.impl.mysql.TapeRecallDAOMySql; -import it.grid.storm.persistence.util.db.DBConnection; -import it.grid.storm.persistence.util.db.DBConnectionPool; -import it.grid.storm.persistence.util.db.DataBaseStrategy; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class MySqlDAOFactory implements DAOFactory { @@ -42,14 +37,8 @@ public class MySqlDAOFactory implements DAOFactory { private static final Logger log = LoggerFactory .getLogger(MySqlDAOFactory.class); - private static final DataBaseStrategy datasource = DataBaseStrategy.MYSQL; - private static DataSourceConnectionFactory connFactory = null; private static MySqlDAOFactory factory = new MySqlDAOFactory(); - static { - MySqlDAOFactory.initializeDataSource(); - } - /** * */ @@ -62,36 +51,6 @@ public static MySqlDAOFactory getInstance() { return MySqlDAOFactory.factory; } - private static void initializeDataSource() { - - Configuration config = Configuration.getInstance(); - - datasource.setDbUrl(config.getBEPersistenceDBMSUrl()); - datasource.setDbName(config.getBEPersistenceDBName()); - datasource.setDbUsr(config.getBEPersistenceDBUserName()); - datasource.setDbPwd(config.getBEPersistenceDBPassword()); - - boolean pool = config.getBEPersistencePoolDB(); - if (pool) { - int maxActive = config.getBEPersistencePoolDBMaxActive(); - int maxWait = config.getBEPersistencePoolDBMaxWait(); - try { - DBConnectionPool.initPool(MySqlDAOFactory.datasource, maxActive, - maxWait); - } catch (PersistenceException e) { - log.error(e.getMessage(), e); - } - MySqlDAOFactory.connFactory = DBConnectionPool.getPoolInstance(); - } else { - try { - MySqlDAOFactory.connFactory = new DBConnection( - MySqlDAOFactory.datasource); - } catch (PersistenceException e) { - log.error(e.getMessage(), e); - } - } - } - /** * Returns an implementation of StorageSpaceCatalog, specific to a particular * datastore. diff --git a/src/main/java/it/grid/storm/persistence/PersistenceDirector.java b/src/main/java/it/grid/storm/persistence/PersistenceDirector.java index 9b262615..855904ac 100644 --- a/src/main/java/it/grid/storm/persistence/PersistenceDirector.java +++ b/src/main/java/it/grid/storm/persistence/PersistenceDirector.java @@ -19,9 +19,9 @@ import it.grid.storm.config.Configuration; import it.grid.storm.persistence.exceptions.PersistenceException; -import it.grid.storm.persistence.util.db.DBConnection; import it.grid.storm.persistence.util.db.DBConnectionPool; import it.grid.storm.persistence.util.db.DataBaseStrategy; +import it.grid.storm.persistence.util.db.Databases; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,69 +29,35 @@ public class PersistenceDirector { private static final Logger log = LoggerFactory.getLogger("persistence"); - private static Configuration config = Configuration.getInstance(); - private static String dbVendor; + private static Configuration config; private static DataBaseStrategy dbMan; private static DAOFactory daoFactory; private static DataSourceConnectionFactory connFactory; static { log.trace("Initializing Persistence Director..."); - dbMan = initializeDataBase(); - daoFactory = initializeFactory(); - connFactory = connectToDateSource(); - } - - private static DataBaseStrategy initializeDataBase() { - - dbVendor = config.getBEPersistenceDBVendor(); - log.debug("DBMS Vendor = {}",dbVendor); - log.debug("DBMS URL = {}", config.getBEPersistenceDBMSUrl()); - return DataBaseStrategy.getInstance(dbVendor); - } - - private static DAOFactory initializeFactory() { + config = Configuration.getInstance(); + dbMan = Databases.getDataBaseStrategy("mysql"); + daoFactory = MySqlDAOFactory.getInstance(); - if (dbVendor.equalsIgnoreCase("MySql")) { - return MySqlDAOFactory.getInstance(); - } - - log.error("Unknown datastore id: {}", dbVendor); - throw new IllegalArgumentException("Unknown datastore identifier: " - +dbVendor); - } - - private static DataSourceConnectionFactory connectToDateSource() { - - DataSourceConnectionFactory result = null; - boolean poolMode = config.getBEPersistencePoolDB(); int maxActive = config.getBEPersistencePoolDBMaxActive(); int maxWait = config.getBEPersistencePoolDBMaxWait(); log.debug("Datasource connection string = {}", dbMan.getConnectionString()); - - log.debug("Pool mode = {}", poolMode); log.debug("Pool Max Active = {}", maxActive); log.debug("Pool Max Wait = {}", maxWait); - if (poolMode) { - try { - DBConnectionPool.initPool(dbMan, maxActive, maxWait); - result = DBConnectionPool.getPoolInstance(); - } catch (PersistenceException e) { - log.error(e.getMessage(), e); - } - } else { - try { - result = new DBConnection(dbMan); - } catch (PersistenceException e) { - log.error(e.getMessage(), e); - } + try { + DBConnectionPool.initPool(dbMan, maxActive, maxWait); + connFactory = DBConnectionPool.getPoolInstance(); + } catch (PersistenceException e) { + log.error(e.getMessage(), e); + System.exit(1); } - return result; } public static DAOFactory getDAOFactory() { + return daoFactory; } diff --git a/src/main/java/it/grid/storm/persistence/util/db/DBConnectionPool.java b/src/main/java/it/grid/storm/persistence/util/db/DBConnectionPool.java index d777f956..afffc834 100644 --- a/src/main/java/it/grid/storm/persistence/util/db/DBConnectionPool.java +++ b/src/main/java/it/grid/storm/persistence/util/db/DBConnectionPool.java @@ -125,7 +125,9 @@ private void init(DataBaseStrategy db, int maxActive, int maxWait) { log.error("Exception while getting driver: {}", ex.getMessage(), ex); } - connectionPoolDatasource.setUrl(db.getConnectionString()); + String connectionString = db.getConnectionString(); + connectionPoolDatasource.setUrl(connectionString); + log.debug("Database connection string: {}", connectionString); connectionPoolDatasource.setUser(db.getDbUsr()); connectionPoolDatasource.setPassword(db.getDbPwd()); @@ -134,6 +136,8 @@ private void init(DataBaseStrategy db, int maxActive, int maxWait) { sharedDatasource.setMaxTotal(maxActive); sharedDatasource.setDefaultMaxWaitMillis(maxWait); + sharedDatasource.setValidationQuery("SELECT 1"); + sharedDatasource.setDefaultTestOnBorrow(true); handle = System.currentTimeMillis(); } diff --git a/src/main/java/it/grid/storm/persistence/util/db/DataBaseStrategy.java b/src/main/java/it/grid/storm/persistence/util/db/DataBaseStrategy.java index 50b26f7b..18fdf6b5 100644 --- a/src/main/java/it/grid/storm/persistence/util/db/DataBaseStrategy.java +++ b/src/main/java/it/grid/storm/persistence/util/db/DataBaseStrategy.java @@ -17,9 +17,6 @@ package it.grid.storm.persistence.util.db; -import java.util.HashMap; -import java.util.Map; - public class DataBaseStrategy { private final String dbmsVendor; @@ -27,28 +24,20 @@ public class DataBaseStrategy { private final String jdbcPrefix; private String dbName; private String dbPrefix; - private String dbUrl; + private String dbHost; private String dbUsr; private String dbPwd; private SQLFormat formatter; + private String properties; - public static final DataBaseStrategy MYSQL = new DataBaseStrategy("mysql", - "com.mysql.cj.jdbc.Driver", "jdbc:mysql://", new MySqlFormat()); - - private static final Map DATABASES = new HashMap(); - - static { - DataBaseStrategy.DATABASES.put(DataBaseStrategy.MYSQL.toString(), - DataBaseStrategy.MYSQL); - } - - private DataBaseStrategy(String dbmsVendor, String driverName, String prefix, + public DataBaseStrategy(String dbmsVendor, String driverName, String prefix, SQLFormat formatter) { this.dbmsVendor = dbmsVendor; this.driverName = driverName; jdbcPrefix = prefix; this.formatter = formatter; + this.properties = ""; } @@ -105,20 +94,22 @@ public String getDbPrefix() { return dbPrefix; } - public void setDbUrl(String url) { + public void setDbHost(String host) { - dbUrl = url; + dbHost = host; } - public String getDbUrl() { + public String getDbHost() { - return dbUrl; + return dbHost; } public String getConnectionString() { - String connStr; - connStr = jdbcPrefix + dbUrl + "/" + dbName; + String connStr = jdbcPrefix + dbHost + "/" + dbName; + if (!properties.isEmpty()) { + connStr += "?" + properties; + } return connStr; } @@ -132,25 +123,14 @@ public SQLFormat getFormatter() { return formatter; } - @Override - public String toString() { - - return dbmsVendor; - } - - - public static DataBaseStrategy getInstance(String vendor) { + public void setProperties(String encodedProperties) { - return DataBaseStrategy.DATABASES.get(vendor); + this.properties = encodedProperties; } - public static String getDriverName(String vendor) { - - return (DataBaseStrategy.getInstance(vendor)).driverName; - } - - public static String getJdbcPrefix(String vendor) { + @Override + public String toString() { - return (DataBaseStrategy.getInstance(vendor)).jdbcPrefix; + return dbmsVendor; } } diff --git a/src/main/java/it/grid/storm/persistence/util/db/Databases.java b/src/main/java/it/grid/storm/persistence/util/db/Databases.java new file mode 100644 index 00000000..ec1109e2 --- /dev/null +++ b/src/main/java/it/grid/storm/persistence/util/db/Databases.java @@ -0,0 +1,35 @@ +package it.grid.storm.persistence.util.db; + +import java.util.Map; + +import com.google.common.collect.Maps; + +import it.grid.storm.config.Configuration; + +public class Databases { + + private static final Map DATABASES = Maps.newHashMap(); + + private static final String MYSQL_VENDOR = "mysql"; + private static final String MYSQL_DRIVER = "com.mysql.cj.jdbc.Driver"; + private static final String MYSQL_PREFIX = "jdbc:mysql://"; + private static final SQLFormat MYSQL_FORMATTER = new MySqlFormat(); + + private static final String DB_NAME = "storm_be_ISAM"; + + static { + Configuration config = Configuration.getInstance(); + DataBaseStrategy dbs = new DataBaseStrategy(MYSQL_VENDOR, MYSQL_DRIVER, MYSQL_PREFIX, MYSQL_FORMATTER); + dbs.setDbUsr(config.getDBUserName()); + dbs.setDbPwd(config.getDBPassword()); + dbs.setProperties(config.getDBProperties()); + dbs.setDbName(DB_NAME); + dbs.setDbHost(config.getDBHostname()); + DATABASES.put(MYSQL_VENDOR, dbs); + } + + public static DataBaseStrategy getDataBaseStrategy(String vendor) { + + return DATABASES.get(vendor); +} +} diff --git a/src/main/java/it/grid/storm/persistence/util/db/SQLHelper.java b/src/main/java/it/grid/storm/persistence/util/db/SQLHelper.java index 5a17d5f4..f246cce5 100644 --- a/src/main/java/it/grid/storm/persistence/util/db/SQLHelper.java +++ b/src/main/java/it/grid/storm/persistence/util/db/SQLHelper.java @@ -25,7 +25,7 @@ public abstract class SQLHelper { protected SQLHelper(String dbmsVendor) { this.dbmsVendor = dbmsVendor; - this.formatter = DataBaseStrategy.getInstance(dbmsVendor).getFormatter(); + this.formatter = Databases.getDataBaseStrategy(dbmsVendor).getFormatter(); } public String format(Object value) {