aboutsummaryrefslogtreecommitdiffstats
path: root/dblib/provider/src/main/java/org/openecomp
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-03-31 15:03:13 -0400
committerDan Timoney <dtimoney@att.com>2017-03-31 15:11:48 -0400
commit974b67dd4021e6e839eaad25366bffe6d7a414c8 (patch)
treec16b969e86323ed8b0914253b1c74d42d31a7ed1 /dblib/provider/src/main/java/org/openecomp
parente0451f75b26082418757f279351c2d3e29c0a5c8 (diff)
[SDNC-5] Rebase sdnc-core
Upgrade to OpenDaylight Boron release, and sync changes made since 16.10 release to ONAP SDN-C distribution Change-Id: I20bef9e6d0008c4436b5624ce839bbb70ecc20a5 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'dblib/provider/src/main/java/org/openecomp')
-rw-r--r--dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/CachedDataSourceFactory.java8
-rw-r--r--dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/DBResourceManager.java20
-rw-r--r--dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/config/DbConfigPool.java4
-rw-r--r--dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractDBResourceManagerFactory.java9
-rw-r--r--dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractResourceManagerFactory.java11
-rw-r--r--dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/DBConfigFactory.java14
-rw-r--r--dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jdbc/JdbcDBCachedDataSource.java252
-rw-r--r--dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jndi/JNDIDbResourceManagerFactory.java167
-rw-r--r--dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jndi/JndiCachedDataSource.java131
9 files changed, 269 insertions, 347 deletions
diff --git a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/CachedDataSourceFactory.java b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/CachedDataSourceFactory.java
index f774748..3e51ed9 100644
--- a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/CachedDataSourceFactory.java
+++ b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/CachedDataSourceFactory.java
@@ -23,9 +23,8 @@ package org.openecomp.sdnc.sli.resource.dblib;
import org.openecomp.sdnc.sli.resource.dblib.config.BaseDBConfiguration;
import org.openecomp.sdnc.sli.resource.dblib.config.JDBCConfiguration;
-import org.openecomp.sdnc.sli.resource.dblib.config.JndiConfiguration;
+import org.openecomp.sdnc.sli.resource.dblib.jdbc.JdbcDBCachedDataSource;
import org.openecomp.sdnc.sli.resource.dblib.jdbc.MySQLCachedDataSource;
-import org.openecomp.sdnc.sli.resource.dblib.jndi.JndiCachedDataSource;
/**
* @version $Revision: 1.1 $
@@ -38,9 +37,8 @@ public class CachedDataSourceFactory {
public static CachedDataSource createDataSource(BaseDBConfiguration config) {
if(config instanceof JDBCConfiguration)
- return MySQLCachedDataSource.createInstance(config);
- if(config instanceof JndiConfiguration)
- return JndiCachedDataSource.createInstance(config);
+ return JdbcDBCachedDataSource.createInstance(config);
+
return (CachedDataSource)null;
}
diff --git a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/DBResourceManager.java b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/DBResourceManager.java
index 7f85c42..401c013 100644
--- a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/DBResourceManager.java
+++ b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/DBResourceManager.java
@@ -53,7 +53,6 @@ import org.openecomp.sdnc.sli.resource.dblib.pm.SQLExecutionMonitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.sun.rowset.providers.RIOptimisticProvider;
/**
* @version $Revision: 1.15 $
@@ -87,7 +86,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
}
return 0;
}
-
+
});
protected final Set<CachedDataSource> broken = Collections.synchronizedSet(new HashSet<CachedDataSource>());
protected final Object monitor = new Object();
@@ -131,17 +130,6 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
worker.setName("DBResourcemanagerWatchThread");
worker.setDaemon(true);
worker.start();
-
- try {
- RIOptimisticProvider rio = new RIOptimisticProvider();
- LOGGER.info("Class " + rio.getClass().getName() + " found.");
- Class clas = this.getClass().getClassLoader().loadClass("com.sun.rowset.providers.RIOptimisticProvider");
- if(clas != null) {
- LOGGER.info("Class " + rio.getClass().getName() + " found by classloader.");
- }
- } catch(Exception exc) {
- LOGGER.info("Failed resolving RIOptimisticProvider class", exc);
- }
}
private void config(Properties ctx) throws Exception {
@@ -320,7 +308,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
Collections.reverse(sources);
}
-
+
// loop through available data sources to retrieve data.
while(!sources.isEmpty())
{
@@ -428,7 +416,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
public boolean writeData(String statement, ArrayList<String> arguments, String preferredDS) throws SQLException {
return writeDataNoRecovery(statement, arguments, preferredDS);
}
-
+
CachedDataSource findMaster() {
CachedDataSource master = null;
CachedDataSource[] dss = this.dsQueue.toArray(new CachedDataSource[0]);
@@ -468,7 +456,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
active = master;
}
}
-
+
return active.writeData(statement, arguments);
} catch(Throwable exc){
String message = exc.getMessage();
diff --git a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/config/DbConfigPool.java b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/config/DbConfigPool.java
index 90ea6bc..117f932 100644
--- a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/config/DbConfigPool.java
+++ b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/config/DbConfigPool.java
@@ -46,10 +46,6 @@ public class DbConfigPool {
return type;
}
- public JndiConfiguration[] getJndiDbSourceArray() {
- return configurations.toArray(new JndiConfiguration[configurations.size()]);
- }
-
public JDBCConfiguration[] getJDBCbSourceArray() {
return configurations.toArray(new JDBCConfiguration[configurations.size()]);
}
diff --git a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractDBResourceManagerFactory.java b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractDBResourceManagerFactory.java
index e6b1a35..f4291a7 100644
--- a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractDBResourceManagerFactory.java
+++ b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractDBResourceManagerFactory.java
@@ -21,7 +21,6 @@
package org.openecomp.sdnc.sli.resource.dblib.factory;
import org.openecomp.sdnc.sli.resource.dblib.jdbc.JdbcDbResourceManagerFactory;
-import org.openecomp.sdnc.sli.resource.dblib.jndi.JNDIDbResourceManagerFactory;
/**
* @version $Revision: 1.1 $
@@ -33,13 +32,7 @@ import org.openecomp.sdnc.sli.resource.dblib.jndi.JNDIDbResourceManagerFactory;
public class AbstractDBResourceManagerFactory {
public static AbstractResourceManagerFactory getFactory(String type) throws FactoryNotDefinedException {
-
- if("JNDI".equals(type)){
- try {
- return JNDIDbResourceManagerFactory.createIntstance();
- } catch (Exception e) {
- }
- }
+
// JDBC
return JdbcDbResourceManagerFactory.createIntstance();
}
diff --git a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractResourceManagerFactory.java b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractResourceManagerFactory.java
index 148ddac..29ec061 100644
--- a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractResourceManagerFactory.java
+++ b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/AbstractResourceManagerFactory.java
@@ -32,7 +32,6 @@ import org.openecomp.sdnc.sli.resource.dblib.DBResourceManager;
import org.openecomp.sdnc.sli.resource.dblib.config.BaseDBConfiguration;
import org.openecomp.sdnc.sli.resource.dblib.config.DbConfigPool;
import org.openecomp.sdnc.sli.resource.dblib.config.JDBCConfiguration;
-import org.openecomp.sdnc.sli.resource.dblib.config.JndiConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,20 +48,15 @@ public abstract class AbstractResourceManagerFactory {
public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager manager) throws Exception;
public abstract CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager dbResourceManager, String sourceName) throws SQLException ;
-
+
public static AbstractResourceManagerFactory createIntstance() throws FactoryNotDefinedException {
throw new FactoryNotDefinedException("Factory method 'createIntstance' needs to be overriden in DBResourceManagerFactory");
}
- public class DBInitTask implements Callable<CachedDataSource>
+ public class DBInitTask implements Callable<CachedDataSource>
{
private BaseDBConfiguration config = null;
private Set<DBInitTask> activeTasks;
-
- public DBInitTask(JndiConfiguration jndiConfig, Set<DBInitTask> tasks){
- this.config = jndiConfig;
- this.activeTasks = tasks;
- }
public DBInitTask(JDBCConfiguration jdbcconfig, Set<DBInitTask> tasks) {
this.config = jdbcconfig;
@@ -97,6 +91,7 @@ public abstract class AbstractResourceManagerFactory {
worker.start();
} else {
if(LOGGER.isDebugEnabled())
+ if(ds != null)
LOGGER.debug("Completed CachedDataSource.Call from "+ds.getDbConnectionName());
}
}
diff --git a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/DBConfigFactory.java b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/DBConfigFactory.java
index 7044082..3530459 100644
--- a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/DBConfigFactory.java
+++ b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/factory/DBConfigFactory.java
@@ -25,10 +25,11 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
+import org.slf4j.LoggerFactory;
+
import org.openecomp.sdnc.sli.resource.dblib.config.BaseDBConfiguration;
import org.openecomp.sdnc.sli.resource.dblib.config.DbConfigPool;
import org.openecomp.sdnc.sli.resource.dblib.config.JDBCConfiguration;
-import org.openecomp.sdnc.sli.resource.dblib.config.JndiConfiguration;
/**
* @version $Revision: 1.1 $
@@ -44,7 +45,7 @@ public class DBConfigFactory {
}
static DbConfigPool getConfigparams(Properties properties){
- org.slf4j.LoggerFactory.getLogger(DBConfigFactory.class).info(properties.toString());
+ LoggerFactory.getLogger(DBConfigFactory.class).info(properties.toString());
DbConfigPool xmlConfig = new DbConfigPool(properties);
ArrayList<Properties> propertySets = new ArrayList<Properties>();
@@ -78,7 +79,7 @@ public class DBConfigFactory {
}
} catch (Exception e) {
- org.slf4j.LoggerFactory.getLogger(DBConfigFactory.class).warn("",e);
+ LoggerFactory.getLogger(DBConfigFactory.class).warn("",e);
}
return xmlConfig;
@@ -89,15 +90,12 @@ public class DBConfigFactory {
String type = props.getProperty(BaseDBConfiguration.DATABASE_TYPE);
BaseDBConfiguration config = null;
-
- if("JNDI".equalsIgnoreCase(type)) {
- config = new JndiConfiguration(props);
- }
+
if("JDBC".equalsIgnoreCase(type)) {
config = new JDBCConfiguration(props);
}
return config;
-
+
}
}
diff --git a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jdbc/JdbcDBCachedDataSource.java b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jdbc/JdbcDBCachedDataSource.java
new file mode 100644
index 0000000..ee3d4ff
--- /dev/null
+++ b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jdbc/JdbcDBCachedDataSource.java
@@ -0,0 +1,252 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openecomp
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 AT&T
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdnc.sli.resource.dblib.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLFeatureNotSupportedException;
+
+import org.apache.tomcat.jdbc.pool.DataSource;
+import org.apache.tomcat.jdbc.pool.PoolProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.openecomp.sdnc.sli.resource.dblib.CachedDataSource;
+import org.openecomp.sdnc.sli.resource.dblib.DBConfigException;
+import org.openecomp.sdnc.sli.resource.dblib.config.BaseDBConfiguration;
+import org.openecomp.sdnc.sli.resource.dblib.config.JDBCConfiguration;
+import com.mysql.jdbc.Driver;
+
+
+/**
+ * @version $Revision: 1.7 $
+ * Change Log
+ * Author Date Comments
+ * ============== ======== ====================================================
+ * Rich Tabedzki
+ */
+
+public class JdbcDBCachedDataSource extends CachedDataSource
+{
+ private String dbUserId;
+ private String dbPasswd;
+ private String dbUrl;
+
+ private int minLimit;
+ private int maxLimit;
+ private int initialLimit;
+
+ private static final String AS_CONF_ERROR = "AS_CONF_ERROR: ";
+
+ private static Logger LOGGER = LoggerFactory.getLogger(JdbcDBCachedDataSource.class);
+
+ /**
+ * @param jdbcElem
+ * @param alarmLog
+ * @param occManager
+ * @throws Exception
+ */
+ public JdbcDBCachedDataSource(BaseDBConfiguration jdbcElem)
+ {
+ super(jdbcElem);
+ }
+
+ @Override
+ protected void configure(BaseDBConfiguration xmlElem) throws DBConfigException
+ {
+ BaseDBConfiguration jdbcConfig = (BaseDBConfiguration)xmlElem;
+ if(jdbcConfig.getConnTimeout() > 0){
+ this.CONN_REQ_TIMEOUT = jdbcConfig.getConnTimeout();
+ }
+ if(jdbcConfig.getRequestTimeout() > 0){
+ this.DATA_REQ_TIMEOUT = jdbcConfig.getRequestTimeout();
+ }
+
+ // set connection pool name
+ String dbConnectionName = jdbcConfig.getDbConnectionName();
+ super.setDbConnectionName(dbConnectionName);
+ // Configure the JDBC connection
+ dbUserId = jdbcConfig.getDbUserId();
+ if (dbUserId == null)
+ {
+ String errorMsg = "Invalid XML contents: JDBCConnection missing dbUserId attribute";
+ LOGGER.error(AS_CONF_ERROR + errorMsg);
+ throw new DBConfigException(errorMsg);
+ }
+
+ dbPasswd = jdbcConfig.getDbPasswd();
+ if (dbPasswd == null)
+ {
+ String errorMsg = "Invalid XML contents: JDBCConnection missing dbPasswd attribute";
+ LOGGER.error(AS_CONF_ERROR + errorMsg);
+ throw new DBConfigException(errorMsg);
+ }
+ /*
+ dbDriver = jdbcConfig.getDbDriver();
+ if (dbDriver == null)
+ {
+ String errorMsg = "Invalid XML contents: JDBCConnection missing dbDriver attribute";
+ LOGGER.error(AS_CONF_ERROR + errorMsg);
+ throw new ScpTblUpdateError(errorMsg);
+ }
+ */
+
+ minLimit = jdbcConfig.getDbMinLimit();
+// if (minLimit == null)
+// {
+// String errorMsg = "Invalid XML contents: JDBC Connection missing minLimit attribute";
+// LOGGER.error(AS_CONF_ERROR + errorMsg);
+// throw new DBConfigException(errorMsg);
+// }
+ maxLimit = jdbcConfig.getDbMaxLimit();
+// if (maxLimit == null)
+// {
+// String errorMsg = "Invalid XML contents: JDBC Connection missing maxLimit attribute";
+// LOGGER.error(AS_CONF_ERROR + errorMsg);
+// throw new DBConfigException(errorMsg);
+// }
+ initialLimit = jdbcConfig.getDbInitialLimit();
+// if (initialLimit == null)
+// {
+// String errorMsg = "Invalid XML contents: JDBC Connection missing initialLimit attribute";
+// LOGGER.error(AS_CONF_ERROR + errorMsg);
+// throw new DBConfigException(errorMsg);
+// }
+
+ dbUrl = jdbcConfig.getDbUrl();
+ if(dbUrl == null){
+ String errorMsg = "Invalid XML contents: JDBCConnection missing dbUrl attribute";
+ LOGGER.error(AS_CONF_ERROR + errorMsg);
+ throw new DBConfigException(errorMsg);
+ }
+
+ try {
+ Driver dr = new com.mysql.jdbc.Driver();
+ Class clazz = Class.forName("com.mysql.jdbc.Driver") ;
+
+ PoolProperties p = new PoolProperties();
+ p.setDriverClassName("com.mysql.jdbc.Driver");
+ p.setUrl(dbUrl);
+ p.setUsername(dbUserId);
+ p.setPassword(dbPasswd);
+ p.setJmxEnabled(true);
+ p.setTestWhileIdle(false);
+ p.setTestOnBorrow(true);
+ p.setValidationQuery("SELECT 1");
+ p.setTestOnReturn(false);
+ p.setValidationInterval(30000);
+ p.setTimeBetweenEvictionRunsMillis(30000);
+ p.setInitialSize(initialLimit);
+ p.setMaxActive(maxLimit);
+ p.setMaxIdle(maxLimit);
+ p.setMaxWait(10000);
+ p.setRemoveAbandonedTimeout(60);
+ p.setMinEvictableIdleTimeMillis(30000);
+ p.setMinIdle(minLimit);
+ p.setLogAbandoned(true);
+ p.setRemoveAbandoned(true);
+ p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
+ + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
+
+ DataSource dataSource = new DataSource(p);
+
+ synchronized(this)
+ {
+ this.ds = dataSource;
+ Connection con = null;
+ PreparedStatement st = null;
+ ResultSet rs = null;
+
+ try {
+ con = dataSource.getConnection();
+ st = con.prepareStatement("Select 1 FROM DUAL");
+ rs = st.executeQuery();
+ } catch(Exception exc) {
+ LOGGER.error(exc.getMessage());
+ } finally {
+ if(rs != null) rs.close();
+ if(st != null) st.close();
+ if(con != null) con.close();
+ }
+
+ initialized = true;
+ LOGGER.info("MySQLDataSource <"+dbConnectionName+"> configured successfully. Using URL: "+dbUrl);
+ }
+
+// } catch (SQLException exc) {
+// initialized = false;
+// StringBuffer sb = new StringBuffer();
+// sb.append("Failed to initialize MySQLDataSource<");
+// sb.append(dbConnectionName).append(">. Reason: ");
+// sb.append(exc.getMessage());
+// LOGGER.error("AS_CONF_ERROR: " + sb.toString());
+//// throw new DBConfigException(e.getMessage());
+ } catch (Exception exc) {
+ initialized = false;
+ StringBuffer sb = new StringBuffer();
+ sb.append("Failed to initialize MySQLCachedDataSource <");
+ sb.append(dbConnectionName).append(">. Reason: ");
+ sb.append(exc.getMessage());
+ LOGGER.error("AS_CONF_ERROR: " + sb.toString());
+// throw new DBConfigException(e.getMessage());
+ }
+ }
+
+ public final String getDbUrl()
+ {
+ return dbUrl;
+ }
+
+ public final String getDbUserId()
+ {
+ return dbUserId;
+ }
+
+ public final String getDbPasswd()
+ {
+ return dbPasswd;
+ }
+
+ public static JdbcDBCachedDataSource createInstance(BaseDBConfiguration config) /*throws Exception*/ {
+ return new JdbcDBCachedDataSource(config);
+ }
+
+ public String toString(){
+ return getDbConnectionName();
+ }
+
+ public java.util.logging.Logger getParentLogger()
+ throws SQLFeatureNotSupportedException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void cleanUp(){
+ DataSource dataSource = (DataSource)ds;
+ dataSource.getPool().purge();
+ int active = dataSource.getActive();
+ int size = dataSource.getSize();
+ dataSource.close(true);
+ super.cleanUp();
+ }
+
+}
diff --git a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jndi/JNDIDbResourceManagerFactory.java b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jndi/JNDIDbResourceManagerFactory.java
deleted file mode 100644
index 2888bc5..0000000
--- a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jndi/JNDIDbResourceManagerFactory.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * openecomp
- * ================================================================================
- * Copyright (C) 2016 - 2017 AT&T
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdnc.sli.resource.dblib.jndi;
-
-import java.sql.SQLException;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
-
-import org.openecomp.sdnc.sli.resource.dblib.CachedDataSource;
-import org.openecomp.sdnc.sli.resource.dblib.CachedDataSourceFactory;
-import org.openecomp.sdnc.sli.resource.dblib.DBResourceManager;
-import org.openecomp.sdnc.sli.resource.dblib.config.DbConfigPool;
-import org.openecomp.sdnc.sli.resource.dblib.config.JndiConfiguration;
-import org.openecomp.sdnc.sli.resource.dblib.factory.AbstractResourceManagerFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @version $Revision: 1.6 $
- * Change Log
- * Author Date Comments
- * ============== ======== ====================================================
- * Rich Tabedzki
- */
-public class JNDIDbResourceManagerFactory extends AbstractResourceManagerFactory {
-
- private static Logger LOGGER = LoggerFactory.getLogger(JNDIDbResourceManagerFactory.class);
-
- class MyFutureTask extends FutureTask<DBInitTask>
- {
-
- public MyFutureTask(Callable<CachedDataSource> result) {
- super((Callable)result);
- }
-
- }
-
- public CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager manager, String sourceName) throws SQLException
- {
- // here create the data sources objects
- JndiConfiguration[] list = dbConfig.getJndiDbSourceArray();
- CachedDataSource[] cachedDS = new CachedDataSource[1];
-
- for(int i=0, max=list.length; i<max; i++){
- if(!sourceName.equals(list[i].getJndiConnectionName()))
- continue;
-
- JndiConfiguration config = list[i];
- CachedDataSource dataSource = CachedDataSourceFactory.createDataSource(config);
- cachedDS[0] = dataSource;
- }
- return cachedDS;
- }
-
- public CachedDataSource[] initDBResourceManager(DbConfigPool dbConfig, DBResourceManager manager) /* throws Exception */ {
-// WSConfigManagement ws = WSConfigManagement.getInstance();
-
- ExecutorService threadExecutor = Executors.newFixedThreadPool(2);
- // here create the data sources objects
- JndiConfiguration[] list = dbConfig.getJndiDbSourceArray();
- FutureTask<DBInitTask>[] futures = new MyFutureTask[list.length];
- final Set<DBInitTask> tasks = new HashSet<DBInitTask>();
- if(LOGGER.isDebugEnabled())
- LOGGER.debug("Creating datasources.");
- for(int i=0, max=list.length; i<max; i++){
- JndiConfiguration config = list[i];
-// if(manager.getJndiContextFactoryStr()!=null && manager.getJndiContextFactoryStr().trim().length()>0){
-// config.setJndiContextFactory(manager.getJndiContextFactoryStr());
-// }
-// if(manager.getJndiURLStr()!=null && manager.getJndiURLStr().trim().length()>0){
-// config.setJndiURL(manager.getJndiURLStr());
-// }
- DBInitTask task = new DBInitTask(config, tasks);
- tasks.add(task);
- futures[i] = new MyFutureTask(task);
- }
-
- try {
- synchronized(tasks){
- for(int i=0, max=list.length; i<max; i++){
- threadExecutor.execute(futures[i]);
- }
- // the timeout param is set is seconds.
- long timeout = ((dbConfig.getTimeout() <= 0) ? 60L : dbConfig.getTimeout());
- timeout *= 1000;
- // the timeout param is set is seconds, hence it needs to be multiplied by 1000.
- tasks.wait(timeout);
- if(LOGGER.isDebugEnabled())
- LOGGER.debug("initDBResourceManager wait completed.");
- }
- } catch(Exception exc) {
- LOGGER.error("Failed to initialize JndiCachedDataSource. Reason: ", exc);
- }
-
- if(threadExecutor != null){
- try {
- threadExecutor.shutdown();
- } catch(Exception exc){}
- }
-
- CachedDataSource[] cachedDS = new CachedDataSource[futures.length];
-
- boolean initialized = false;
- for(int i=0; i<futures.length; i++){
- Object obj = null;
- if(futures[i].isDone()){
- try {
- obj = futures[i].get();
- if(obj instanceof CachedDataSource){
- cachedDS[i] = (CachedDataSource)obj;
- initialized = true;
- LOGGER.info("DataSource "+list[i].getJndiConnectionName()+" initialized successfully");
- }
- } catch (InterruptedException exc) {
- LOGGER.error("DataSource "+list[i].getJndiConnectionName()+" initialization failed", exc);
- } catch (ExecutionException exc) {
- LOGGER.error("DataSource "+list[i].getJndiConnectionName()+" initialization failed", exc);
- } catch (Exception exc) {
- LOGGER.error("DataSource "+list[i].getJndiConnectionName()+" initialization failed", exc);
- }
- } else {
- try {
- obj = futures[i].get();
- if(obj instanceof CachedDataSource){
-
- LOGGER.error("DataSource "+((CachedDataSource)obj).getDbConnectionName()+" failed");
- }
- } catch (Exception exc) {
- LOGGER.error("DataSource "+list[i].getJndiConnectionName()+" initialization failed", exc);
- }
- }
- }
-
- if(!initialized){
- new Error("Failed to initialize DB Library.");
- }
- return cachedDS;
- }
-
- public static AbstractResourceManagerFactory createIntstance() {
- return new JNDIDbResourceManagerFactory();
- }
-
-}
diff --git a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jndi/JndiCachedDataSource.java b/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jndi/JndiCachedDataSource.java
deleted file mode 100644
index 19fa8e9..0000000
--- a/dblib/provider/src/main/java/org/openecomp/sdnc/sli/resource/dblib/jndi/JndiCachedDataSource.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * openecomp
- * ================================================================================
- * Copyright (C) 2016 - 2017 AT&T
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdnc.sli.resource.dblib.jndi;
-
-import java.sql.SQLFeatureNotSupportedException;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.openecomp.sdnc.sli.resource.dblib.CachedDataSource;
-import org.openecomp.sdnc.sli.resource.dblib.DBConfigException;
-import org.openecomp.sdnc.sli.resource.dblib.config.BaseDBConfiguration;
-import org.openecomp.sdnc.sli.resource.dblib.config.JndiConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.SAXException;
-
-/**
- * @version $Revision: 1.2 $
- * Change Log
- * Author Date Comments
- * ============== ======== ====================================================
- * Rich Tabedzki
- */
-public class JndiCachedDataSource extends CachedDataSource
-{
- private static Logger LOGGER = LoggerFactory.getLogger(JndiCachedDataSource.class);
- /**
- * @param alarmLog
- * @param jdbcElem
- * @throws SAXException
- * @throws ScpTblUpdateError
- */
- public JndiCachedDataSource(BaseDBConfiguration xmlElem) throws DBConfigException
- {
- super(xmlElem);
- }
-
- protected void configure(BaseDBConfiguration xmlElem) throws DBConfigException {
- JndiConfiguration jdbcConfig = (JndiConfiguration)xmlElem;
- String jndiContextFactoryStr = jdbcConfig.getJndiContextFactory();
- String jndiURLStr = jdbcConfig.getJndiURL();
- String jndiSourceStr = jdbcConfig.getJndiSource();
-
- if(jdbcConfig.getConnTimeout() > 0){
- this.CONN_REQ_TIMEOUT = jdbcConfig.getConnTimeout();
- }
- if(jdbcConfig.getRequestTimeout() > 0){
- this.DATA_REQ_TIMEOUT = jdbcConfig.getRequestTimeout();
- }
-
- super.setDbConnectionName(jdbcConfig.getJndiConnectionName());
-
- if(jndiContextFactoryStr == null || jndiContextFactoryStr.length() == 0)
- {
-// throw new DBConfigException("The jndi configuration is incomplete: jndiContextFactory");
- }
- if(jndiURLStr == null || jndiContextFactoryStr.length() == 0)
- {
-// throw new ScpTblUpdateError("The jndi configuration is incomplete: jndiURL");
- }
- if(jndiSourceStr == null || jndiSourceStr.length() == 0)
- {
- throw new DBConfigException("The jndi configuration is incomplete: jndiSource");
- }
-
- Properties env = new Properties();
- Context ctx;
- try
- {
- if(jndiContextFactoryStr != null && jndiContextFactoryStr.length() != 0){
- env.put(Context.INITIAL_CONTEXT_FACTORY, jndiContextFactoryStr);
- ctx = new InitialContext(env);
- } else {
- ctx = new InitialContext();
- }
- ds = (javax.sql.DataSource) ctx.lookup (jndiSourceStr);
- if(ds == null)
- {
- this.initialized = false;
- LOGGER.error("AS_CONF_ERROR: Failed to initialize DataSource <"+getDbConnectionName()+"> using JNDI <"+jndiSourceStr+">");
- return;
- } else {
- this.initialized = true;
- LOGGER.info("JndiCachedDataSource <"+getDbConnectionName()+"> configured successfully.");
- return;
- }
- } catch (NamingException exc) {
- this.initialized = false;
- LOGGER.error("AS_CONF_ERROR" + exc.getMessage());
-
- } catch(Throwable exc) {
- this.initialized = false;
- LOGGER.error("AS_CONF_ERROR: " + exc.getMessage());
- }
- }
-
- public static JndiCachedDataSource createInstance(BaseDBConfiguration config) {
- return new JndiCachedDataSource(config);
- }
-
- public String toString(){
- return getDbConnectionName();
- }
-
- public java.util.logging.Logger getParentLogger()
- throws SQLFeatureNotSupportedException {
- // TODO Auto-generated method stub
- return null;
- }
-}