Commit 9b2f29e6 9b2f29e6e4766dca1d5c8b9fdb9ec2c9b442d038 by Christian Gerdes

PDB koden funkar halvvägs, kvar att implementera är cachningen.

Lagt till stöd för att hantera TNS connection strängar, testat att det
funkar.
PDB namnet visas nu korrekt i JavaMonWeb för OraMon då
getDBName() returnerar PDB namnet om det är en PDB
1 parent 428225ca
......@@ -53,27 +53,44 @@ public class OraMonRESTgetData extends HttpServlet {
if(shortConArray.length != 2) {
// Error, wrong format of string
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format jdbc:oracle:thin:@//host:port/servicename with optional :username:password at the end.\"}");
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format jdbc:oracle:thin:@//host:port/servicename or jdbc:oracle:thin:@(<TNS Connection String>) with optional :username:password at the end.\"}");
return;
}
String[] shortConArray2 = shortConArray[1].split(":");
if(shortConArray2[0].startsWith("//") && shortConArray2.length == 4) {
// We have new style and username and password, we can try to create the monitor if it doesnt exist
monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1], shortConArray2[2], shortConArray2[3]);
} else if(!shortConArray2[0].startsWith("//") && shortConArray2.length == 5) {
// We have old style with sid with :username:password, try to find or create it
monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2], shortConArray2[3], shortConArray2[4]);
} else if(shortConArray2[0].startsWith("//") && shortConArray2.length == 2) {
// We have new style but only have the connection string, try to find it (we cant create one without username/password)
monitor = Registry.find(request.getParameter("connectionString"));
} else if(!shortConArray2[0].startsWith("//") && shortConArray2.length == 3) {
// We have old style sid and no :username:password
monitor = Registry.find(request.getParameter("connectionString"));
if(shortConArray2[0].startsWith("(")) {
// TNS Format
if(shortConArray2.length == 3) {
// We have a TNS connection string and username + password
monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0], shortConArray2[1], shortConArray2[2]);
} else if (shortConArray2.length == 1) {
// We only have the TNS connection string, no username or password
monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0]);
} else {
// We have something else, not implemented
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format jdbc:oracle:thin:@(<TNS Connection String>) with optional :username:password at the end.\"}");
return;
}
} else {
// Wrong format
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format jdbc:oracle:thin:@//host:port/servicename with optional :username:password at the end.\"}");
return;
// JDBC Format
if(shortConArray2[0].startsWith("//") && shortConArray2.length == 4) {
// We have new style and username and password, we can try to create the monitor if it doesnt exist
monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1], shortConArray2[2], shortConArray2[3]);
} else if(!shortConArray2[0].startsWith("//") && shortConArray2.length == 5) {
// We have old style with sid with :username:password, try to find or create it
monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2], shortConArray2[3], shortConArray2[4]);
} else if(shortConArray2[0].startsWith("//") && shortConArray2.length == 2) {
// We have new style but only have the connection string, try to find it (we cant create one without username/password)
monitor = Registry.find(request.getParameter("connectionString"));
} else if(!shortConArray2[0].startsWith("//") && shortConArray2.length == 3) {
// We have old style sid and no :username:password
monitor = Registry.find(request.getParameter("connectionString"));
} else {
// Wrong format
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format jdbc:oracle:thin:@//host:port/servicename with optional :username:password at the end.\"}");
return;
}
}
} else {
// Short con string
......
......@@ -45,31 +45,44 @@ public class OraMonRESTgetMetrics extends HttpServlet {
if(shortConArray.length != 2) {
// Error, wrong format of string
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format jdbc:oracle:thin:@//host:port/servicename with optional :username:password at the end.\"}");
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format jdbc:oracle:thin:@//host:port/servicename or jdbc:oracle:thin:@(<TNS Connection String>) with optional :username:password at the end.\"}");
return;
}
String[] shortConArray2 = shortConArray[1].split(":");
if(shortConArray2[0].startsWith("//") && (shortConArray2.length == 4 || shortConArray2.length == 2)) {
// We seem to have a correct connection string, if :username:password exist we ignore them here
monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]);
if(monitor == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]+"\"}");
return;
if(shortConArray2[0].startsWith("(")) {
// TNS Format
if(shortConArray2.length >= 1) {
monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0]);
if(monitor == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0]+"\"}");
return;
}
}
} else if(!shortConArray2[0].startsWith("//") && (shortConArray2.length == 5 || shortConArray2.length == 3)) {
// We seem to have a correct connection string, if :username:password exist we ignore them here
monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2]);
if(monitor == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2]+"\"}");
} else {
// JDBC Format
if(shortConArray2[0].startsWith("//") && (shortConArray2.length == 4 || shortConArray2.length == 2)) {
// We seem to have a correct connection string, if :username:password exist we ignore them here
monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]);
if(monitor == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]+"\"}");
return;
}
} else if(!shortConArray2[0].startsWith("//") && (shortConArray2.length == 5 || shortConArray2.length == 3)) {
// We seem to have a correct connection string, if :username:password exist we ignore them here
monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2]);
if(monitor == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2]+"\"}");
return;
}
} else {
// Wrong format
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format jdbc:oracle:thin:@//host:port/servicename with optional :username:password at the end.\"}");
return;
}
} else {
// Wrong format
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().println("{\"error\":true,\"msg\":\"connectionString needs to be in format jdbc:oracle:thin:@//host:port/servicename with optional :username:password at the end.\"}");
return;
}
} else {
// Check that we have a valid connection string (old style)
......
......@@ -228,12 +228,7 @@ public class OraMon {
public boolean getData(long ageTs) throws Throwable {
//Check age
if ((System.nanoTime() - lastFetchTSns) < (ageTs * 1000 * 1000 * 1000)) return false;
//Bail out if we are a PDB and ask the CDB OraMon object to update us
if(isPDB) {
if(containerDB != null) return containerDB.getData(ageTs);
// If we get here its strange. We know we are a PDB but we have no CDB object.
// Lets see if we ever end up here ;)
}
// Start thread safe
// Try to get a lock
boolean haveLock = lock.tryLock();
......@@ -296,11 +291,11 @@ public class OraMon {
}
// If we have containers, but we are not the CDB, then we are a PDB.
// We should as the CDB object for our data
if(isPDB) {
// We should ask the CDB object for our data
if(isPDB && false) {
// TODO: Find the CDB OraMon object, get the data we need from it's cached CON tables
} else {
// All other cases (CDB or an instance without containers)
// 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"));
......@@ -311,7 +306,6 @@ public class OraMon {
// 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
......
......@@ -28,6 +28,8 @@ public class TestRunner {
System.out.println("getData returned: " + mon.getData());
System.out.println("getDatabaseName: " + mon.getDBName());
System.out.println("getServiceName: " + mon.getServiceName());
System.out.println("getServiceName: " + mon.getConString());
System.out.println("getNumberOfCPUs: " + mon.getNumberOfCPUs());
}
public static void runner1() throws Throwable {
......