Commit 3a16c54c 3a16c54cdc9cef2166b3197dc04be3c9b953a62b by Christian Gerdes

Tagit bort PDB koden. Kommer byta till ny approuch. TNS stödet kvar.

PDB som ska cachas får alltid gå via CDB Connection String och istället
får man skicka med en flagga med PDB namnet som man vill ha ut. Blir
mycket enklare.
1 parent 0d1c6605
package se.lil.om;
import java.sql.*;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Properties;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
......@@ -22,8 +20,6 @@ public class OraMon {
Boolean hasContainers = null;
OraMon containerDB = null;
private Hashtable<String, OraMon> myPDBs = null;
public static final int SYSSTAT = 1;
public static final int OSSTAT = 2;
......@@ -276,60 +272,28 @@ public class OraMon {
rset.close();
}
// Check if we can have containers
if(hasContainers == null) {
// We don't know, check if the CONTAINERS view exists in the database
rset = stmt.executeQuery("select count(*) from SYS.ALL_VIEWS where VIEW_NAME = 'V_$CONTAINERS'");
if(rset.next()) {
if(rset.getInt(1) == 1) {
// We found the containers view. Enable container handling
hasContainers = true;
String serviceName = getServiceName();
if(serviceName != null) {
if(serviceName.equals(this.dbName)) isCDB = true;
else isPDB = true;
} else {
// Servicename is null, treat as CDB
isCDB = true;
isPDB = false;
}
}
}
if(hasContainers == null) {
hasContainers = false;
isCDB = true;
isPDB = false;
}
}
// All other cases (CDB or an instance without containers) get the data from the database
// If we have containers, but we are not the CDB, then we are a PDB.
// We should ask the CDB object for our data
if(isPDB) {
getDataFromCDB(ageTs);
} else {
// All other cases (CDB or an instance without containers) get the data from the database
//Get the entire V_$OSSTAT table from DB
colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT"));
//Set numCpus
this.numCpus = (int) colOsStat.getCurrentValue("NUM_CPUS");
// Get OS Load
osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'"));
// SYSSTAT and SYS_TIME_MODEL are specific for PDB and CDB/Instance is the total.
// Get DB CPU use time
rset = stmt.executeQuery("select systimestamp, s.value as NIWT, t.value as DBCPU from V$SYSSTAT s, V$SYS_TIME_MODEL t where s.name='non-idle wait time' and t.STAT_NAME='DB CPU'");
rset.next();
niwTime.update(rset.getLong(2), rset.getTimestamp(1));
cpuTime.update(rset.getLong(3), rset.getTimestamp(1));
rset.close();
//Get the entire V_$SYSSTAT table from DB
colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
}
//Get the entire V_$OSSTAT table from DB
colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT"));
//Set numCpus
this.numCpus = (int) colOsStat.getCurrentValue("NUM_CPUS");
// Get OS Load
osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'"));
// SYSSTAT and SYS_TIME_MODEL are specific for PDB and CDB/Instance is the total.
// Get DB CPU use time
rset = stmt.executeQuery("select systimestamp, s.value as NIWT, t.value as DBCPU from V$SYSSTAT s, V$SYS_TIME_MODEL t where s.name='non-idle wait time' and t.STAT_NAME='DB CPU'");
rset.next();
niwTime.update(rset.getLong(2), rset.getTimestamp(1));
cpuTime.update(rset.getLong(3), rset.getTimestamp(1));
rset.close();
//Get the entire V_$SYSSTAT table from DB
colSysStat.update(stmt.executeQuery("select systimestamp, name, value from V$SYSSTAT"));
stmt.close();
getDataSucess++;
......@@ -355,21 +319,6 @@ public class OraMon {
// End thread safe
}
public void getDataFromCDB(long ageTs) throws Throwable {
//Generate a con string for the CDB using the PDB con string and replace the service name
String cdbConString = getConString().replaceAll(getServiceName(), getDBName());
System.out.println("CDB seems to be: " + cdbConString);
//Find the CDB in the registry
OraMon myCDB = Registry.findOrCreate(cdbConString, conUser, conPass);
myCDB.getData(ageTs);
// Verify the CDB
if (getDBName().equals(myCDB.getDBName())) {
System.out.println("myCDB name equals DBName");
} else {
System.out.println("myCDB name does not equal DBName");
}
}
public Throwable getLastEx() {
return lastEx;
}
......
......@@ -24,7 +24,8 @@ public class TestRunner {
}
public static void testTns() throws Throwable {
OraMon mon = new OraMon("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=u00153.kap.rsv.se)(Port=1526))(ADDRESS=(PROTOCOL=TCP)(Host=u00154.kap.rsv.se)(Port=1526)))(CONNECT_DATA=(SERVICE_NAME=PB1K001)))","dbsnmp","dbsnmp"); // PDB using TNS
//OraMon mon = new OraMon("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=u00153.kap.rsv.se)(Port=1526))(ADDRESS=(PROTOCOL=TCP)(Host=u00154.kap.rsv.se)(Port=1526)))(CONNECT_DATA=(SERVICE_NAME=PB1K001)))","dbsnmp","dbsnmp"); // PDB using TNS
OraMon mon = new OraMon("jdbc:oracle:thin:@//u00153.kap.rsv.se:1526/DB1K01","dbsnmp","dbsnmp");
System.out.println("getData returned: " + mon.getData());
System.out.println("getDatabaseName: " + mon.getDBName());
System.out.println("getServiceName: " + mon.getServiceName());
......@@ -41,7 +42,8 @@ public class TestRunner {
//OraMon mon1 = new OraMon("jdbc:oracle:thin:@uvp3dbkappkg:1550:VP1K03","dbsnmp","dbsnmp"); // SID eller Service Name format
//OraMon mon1 = new OraMon("jdbc:oracle:thin:@//u00154.kap.rsv.se:1526/DB1K01","dbsnmp","dbsnmp");
OraMon mon1 = new OraMon("jdbc:oracle:thin:@//u03634.kap.rsv.se:1526/DA1K001","dbsnmp","dbsnmp");
OraMon mon1 = new OraMon("jdbc:oracle:thin:@//u03634.kap.rsv.se:1526/DA1K001","dbsnmp","dbsnmp"); // PDB, CDB är DB1K12
//OraMon mon1 = new OraMon("jdbc:oracle:thin:@//u03634.kap.rsv.se:1526/DA1K002","dbsnmp","dbsnmp"); // Andra PDB på CDB DB1K12
//OraMon mon2 = new OraMon("jdbc:oracle:thin:@host:port:sid","user","pass"); // SID format
mon1.open();
//mon2.open();
......