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,10 +53,26 @@ public class OraMonRESTgetData extends HttpServlet { ...@@ -53,10 +53,26 @@ public class OraMonRESTgetData extends HttpServlet {
53 if(shortConArray.length != 2) { 53 if(shortConArray.length != 2) {
54 // Error, wrong format of string 54 // Error, wrong format of string
55 response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 55 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
56 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.\"}"); 56 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.\"}");
57 return; 57 return;
58 } 58 }
59 String[] shortConArray2 = shortConArray[1].split(":"); 59 String[] shortConArray2 = shortConArray[1].split(":");
60 if(shortConArray2[0].startsWith("(")) {
61 // TNS Format
62 if(shortConArray2.length == 3) {
63 // We have a TNS connection string and username + password
64 monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0], shortConArray2[1], shortConArray2[2]);
65 } else if (shortConArray2.length == 1) {
66 // We only have the TNS connection string, no username or password
67 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0]);
68 } else {
69 // We have something else, not implemented
70 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
71 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.\"}");
72 return;
73 }
74 } else {
75 // JDBC Format
60 if(shortConArray2[0].startsWith("//") && shortConArray2.length == 4) { 76 if(shortConArray2[0].startsWith("//") && shortConArray2.length == 4) {
61 // We have new style and username and password, we can try to create the monitor if it doesnt exist 77 // We have new style and username and password, we can try to create the monitor if it doesnt exist
62 monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1], shortConArray2[2], shortConArray2[3]); 78 monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1], shortConArray2[2], shortConArray2[3]);
...@@ -75,6 +91,7 @@ public class OraMonRESTgetData extends HttpServlet { ...@@ -75,6 +91,7 @@ public class OraMonRESTgetData extends HttpServlet {
75 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.\"}"); 91 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.\"}");
76 return; 92 return;
77 } 93 }
94 }
78 } else { 95 } else {
79 // Short con string 96 // Short con string
80 // Check that we have a valid connection string (added support to handle diffrent kinds of connection strings) 97 // Check that we have a valid connection string (added support to handle diffrent kinds of connection strings)
......
...@@ -45,10 +45,22 @@ public class OraMonRESTgetMetrics extends HttpServlet { ...@@ -45,10 +45,22 @@ public class OraMonRESTgetMetrics extends HttpServlet {
45 if(shortConArray.length != 2) { 45 if(shortConArray.length != 2) {
46 // Error, wrong format of string 46 // Error, wrong format of string
47 response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 47 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
48 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.\"}"); 48 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.\"}");
49 return; 49 return;
50 } 50 }
51 String[] shortConArray2 = shortConArray[1].split(":"); 51 String[] shortConArray2 = shortConArray[1].split(":");
52 if(shortConArray2[0].startsWith("(")) {
53 // TNS Format
54 if(shortConArray2.length >= 1) {
55 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0]);
56 if(monitor == null) {
57 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
58 response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0]+"\"}");
59 return;
60 }
61 }
62 } else {
63 // JDBC Format
52 if(shortConArray2[0].startsWith("//") && (shortConArray2.length == 4 || shortConArray2.length == 2)) { 64 if(shortConArray2[0].startsWith("//") && (shortConArray2.length == 4 || shortConArray2.length == 2)) {
53 // We seem to have a correct connection string, if :username:password exist we ignore them here 65 // We seem to have a correct connection string, if :username:password exist we ignore them here
54 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]); 66 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]);
...@@ -71,6 +83,7 @@ public class OraMonRESTgetMetrics extends HttpServlet { ...@@ -71,6 +83,7 @@ public class OraMonRESTgetMetrics extends HttpServlet {
71 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.\"}"); 83 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.\"}");
72 return; 84 return;
73 } 85 }
86 }
74 } else { 87 } else {
75 // Check that we have a valid connection string (old style) 88 // Check that we have a valid connection string (old style)
76 String[] conStrParamArray = request.getParameter("connectionString").split(":"); 89 String[] conStrParamArray = request.getParameter("connectionString").split(":");
......
...@@ -228,12 +228,7 @@ public class OraMon { ...@@ -228,12 +228,7 @@ public class OraMon {
228 public boolean getData(long ageTs) throws Throwable { 228 public boolean getData(long ageTs) throws Throwable {
229 //Check age 229 //Check age
230 if ((System.nanoTime() - lastFetchTSns) < (ageTs * 1000 * 1000 * 1000)) return false; 230 if ((System.nanoTime() - lastFetchTSns) < (ageTs * 1000 * 1000 * 1000)) return false;
231 //Bail out if we are a PDB and ask the CDB OraMon object to update us 231
232 if(isPDB) {
233 if(containerDB != null) return containerDB.getData(ageTs);
234 // If we get here its strange. We know we are a PDB but we have no CDB object.
235 // Lets see if we ever end up here ;)
236 }
237 // Start thread safe 232 // Start thread safe
238 // Try to get a lock 233 // Try to get a lock
239 boolean haveLock = lock.tryLock(); 234 boolean haveLock = lock.tryLock();
...@@ -296,11 +291,11 @@ public class OraMon { ...@@ -296,11 +291,11 @@ public class OraMon {
296 } 291 }
297 292
298 // If we have containers, but we are not the CDB, then we are a PDB. 293 // If we have containers, but we are not the CDB, then we are a PDB.
299 // We should as the CDB object for our data 294 // We should ask the CDB object for our data
300 if(isPDB) { 295 if(isPDB && false) {
301 // TODO: Find the CDB OraMon object, get the data we need from it's cached CON tables 296 // TODO: Find the CDB OraMon object, get the data we need from it's cached CON tables
302 } else { 297 } else {
303 // All other cases (CDB or an instance without containers) 298 // All other cases (CDB or an instance without containers) get the data from the database
304 299
305 //Get the entire V_$OSSTAT table from DB 300 //Get the entire V_$OSSTAT table from DB
306 colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT")); 301 colOsStat.update(stmt.executeQuery("select systimestamp, stat_name, value from V$OSSTAT"));
...@@ -311,7 +306,6 @@ public class OraMon { ...@@ -311,7 +306,6 @@ public class OraMon {
311 // Get OS Load 306 // Get OS Load
312 osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'")); 307 osLoad.update(stmt.executeQuery("select systimestamp, value from V$OSSTAT where stat_name='LOAD'"));
313 308
314
315 // SYSSTAT and SYS_TIME_MODEL are specific for PDB and CDB/Instance is the total. 309 // SYSSTAT and SYS_TIME_MODEL are specific for PDB and CDB/Instance is the total.
316 310
317 // Get DB CPU use time 311 // Get DB CPU use time
......
...@@ -28,6 +28,8 @@ public class TestRunner { ...@@ -28,6 +28,8 @@ public class TestRunner {
28 System.out.println("getData returned: " + mon.getData()); 28 System.out.println("getData returned: " + mon.getData());
29 System.out.println("getDatabaseName: " + mon.getDBName()); 29 System.out.println("getDatabaseName: " + mon.getDBName());
30 System.out.println("getServiceName: " + mon.getServiceName()); 30 System.out.println("getServiceName: " + mon.getServiceName());
31 System.out.println("getServiceName: " + mon.getConString());
32 System.out.println("getNumberOfCPUs: " + mon.getNumberOfCPUs());
31 } 33 }
32 34
33 public static void runner1() throws Throwable { 35 public static void runner1() throws Throwable {
......