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 { ...@@ -53,27 +53,44 @@ 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("//") && shortConArray2.length == 4) { 60 if(shortConArray2[0].startsWith("(")) {
61 // We have new style and username and password, we can try to create the monitor if it doesnt exist 61 // TNS Format
62 monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1], shortConArray2[2], shortConArray2[3]); 62 if(shortConArray2.length == 3) {
63 } else if(!shortConArray2[0].startsWith("//") && shortConArray2.length == 5) { 63 // We have a TNS connection string and username + password
64 // We have old style with sid with :username:password, try to find or create it 64 monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0], shortConArray2[1], shortConArray2[2]);
65 monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2], shortConArray2[3], shortConArray2[4]); 65 } else if (shortConArray2.length == 1) {
66 } else if(shortConArray2[0].startsWith("//") && shortConArray2.length == 2) { 66 // We only have the TNS connection string, no username or password
67 // We have new style but only have the connection string, try to find it (we cant create one without username/password) 67 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0]);
68 monitor = Registry.find(request.getParameter("connectionString")); 68 } else {
69 } else if(!shortConArray2[0].startsWith("//") && shortConArray2.length == 3) { 69 // We have something else, not implemented
70 // We have old style sid and no :username:password 70 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
71 monitor = Registry.find(request.getParameter("connectionString")); 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 }
72 } else { 74 } else {
73 // Wrong format 75 // JDBC Format
74 response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 76 if(shortConArray2[0].startsWith("//") && shortConArray2.length == 4) {
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.\"}"); 77 // We have new style and username and password, we can try to create the monitor if it doesnt exist
76 return; 78 monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1], shortConArray2[2], shortConArray2[3]);
79 } else if(!shortConArray2[0].startsWith("//") && shortConArray2.length == 5) {
80 // We have old style with sid with :username:password, try to find or create it
81 monitor = Registry.findOrCreate(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2], shortConArray2[3], shortConArray2[4]);
82 } else if(shortConArray2[0].startsWith("//") && shortConArray2.length == 2) {
83 // We have new style but only have the connection string, try to find it (we cant create one without username/password)
84 monitor = Registry.find(request.getParameter("connectionString"));
85 } else if(!shortConArray2[0].startsWith("//") && shortConArray2.length == 3) {
86 // We have old style sid and no :username:password
87 monitor = Registry.find(request.getParameter("connectionString"));
88 } else {
89 // Wrong format
90 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
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.\"}");
92 return;
93 }
77 } 94 }
78 } else { 95 } else {
79 // Short con string 96 // Short con string
......
...@@ -45,31 +45,44 @@ public class OraMonRESTgetMetrics extends HttpServlet { ...@@ -45,31 +45,44 @@ 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("//") && (shortConArray2.length == 4 || shortConArray2.length == 2)) { 52 if(shortConArray2[0].startsWith("(")) {
53 // We seem to have a correct connection string, if :username:password exist we ignore them here 53 // TNS Format
54 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]); 54 if(shortConArray2.length >= 1) {
55 if(monitor == null) { 55 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0]);
56 response.setStatus(HttpServletResponse.SC_NOT_FOUND); 56 if(monitor == null) {
57 response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]+"\"}"); 57 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
58 return; 58 response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0]+"\"}");
59 return;
60 }
59 } 61 }
60 } else if(!shortConArray2[0].startsWith("//") && (shortConArray2.length == 5 || shortConArray2.length == 3)) { 62 } else {
61 // We seem to have a correct connection string, if :username:password exist we ignore them here 63 // JDBC Format
62 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2]); 64 if(shortConArray2[0].startsWith("//") && (shortConArray2.length == 4 || shortConArray2.length == 2)) {
63 if(monitor == null) { 65 // We seem to have a correct connection string, if :username:password exist we ignore them here
64 response.setStatus(HttpServletResponse.SC_NOT_FOUND); 66 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]);
65 response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2]+"\"}"); 67 if(monitor == null) {
68 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
69 response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1]+"\"}");
70 return;
71 }
72 } else if(!shortConArray2[0].startsWith("//") && (shortConArray2.length == 5 || shortConArray2.length == 3)) {
73 // We seem to have a correct connection string, if :username:password exist we ignore them here
74 monitor = Registry.find(shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2]);
75 if(monitor == null) {
76 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
77 response.getWriter().println("{\"error\":true,\"msg\":\"Can not find a monitor with connection string "+shortConArray[0] + "@" + shortConArray2[0] + ":" + shortConArray2[1] + ":" + shortConArray2[2]+"\"}");
78 return;
79 }
80 } else {
81 // Wrong format
82 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
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.\"}");
66 return; 84 return;
67 } 85 }
68 } else {
69 // Wrong format
70 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
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.\"}");
72 return;
73 } 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)
......
...@@ -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 {
......