You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ec...@apache.org on 2007/12/05 21:57:34 UTC
svn commit: r601520 - in
/geronimo/sandbox/monitoring/client/client-war/src/main:
java/org/apache/geronimo/plugins/monitoring/client/ webapp/WEB-INF/view/
Author: ecraig
Date: Wed Dec 5 12:57:32 2007
New Revision: 601520
URL: http://svn.apache.org/viewvc?rev=601520&view=rev
Log:
GERONIMO-3676
monitoring client throws an error message when there are no graphs
present
Patch by Viet Nguyen
Modified:
geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java
geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java
geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp
geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditView.jsp
Modified: geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java?rev=601520&r1=601519&r2=601520&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java (original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MRCConnector.java Wed Dec 5 12:57:32 2007
@@ -62,18 +62,20 @@
{
// decrypt the password
password = (String)EncryptionManager.decrypt(password);
-
- Properties props = new Properties();
- props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
- "org.apache.openejb.client.RemoteInitialContextFactory");
- props.setProperty(Context.PROVIDER_URL, "ejbd://" + ip + ":4201");
- props.setProperty(Context.SECURITY_PRINCIPAL, userName);
- props.setProperty(Context.SECURITY_CREDENTIALS, password);
- props.setProperty("openejb.authentication.realmName", "geronimo-admin");
- Context ic = new InitialContext(props);
- mrc = (MasterRemoteControlRemote) ic.lookup("ejb/mgmt/MRCRemote");
- mrc.setUpMEJB(userName, password);
-
+ try {
+ Properties props = new Properties();
+ props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.openejb.client.RemoteInitialContextFactory");
+ props.setProperty(Context.PROVIDER_URL, "ejbd://" + ip + ":4201");
+ props.setProperty(Context.SECURITY_PRINCIPAL, userName);
+ props.setProperty(Context.SECURITY_CREDENTIALS, password);
+ props.setProperty("openejb.authentication.realmName", "geronimo-admin");
+ Context ic = new InitialContext(props);
+ mrc = (MasterRemoteControlRemote) ic.lookup("ejb/mgmt/MRCRemote");
+ mrc.setUpMEJB(userName, password);
+ } catch(Exception e) {
+ throw e;
+ }
// when the code has reach this point, a connection was successfully established
// so we need to update the last_seen attribute for the server
Format formatter = null;
Modified: geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java?rev=601520&r1=601519&r2=601520&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java (original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java Wed Dec 5 12:57:32 2007
@@ -572,6 +572,9 @@
String name = actionRequest.getParameter("name");
String description = actionRequest.getParameter("description");
String[] graphsArray = actionRequest.getParameterValues("graph_ids");
+ if(graphsArray == null) {
+ graphsArray = new String[0];
+ }
try
{
PreparedStatement pStmt = con
@@ -617,8 +620,10 @@
String name = actionRequest.getParameter("name");
String description = actionRequest.getParameter("description");
String[] graphsArray = actionRequest.getParameterValues("graph_ids");
- try
- {
+ if(graphsArray == null) {
+ graphsArray = new String[0];
+ }
+ try {
PreparedStatement pStmt = con
.prepareStatement("INSERT INTO views (name, description, graph_count, modified, added) VALUES ('"
+ name
@@ -631,32 +636,28 @@
pStmt = con
.prepareStatement("select view_id from views ORDER BY view_id DESC");
ResultSet rs = pStmt.executeQuery();
- if (rs.next())
- {
+ if (rs.next()) {
Integer view_id = rs.getInt("view_id");
-
- if (graphsArray != null)
- for (int i = 0; i < graphsArray.length; i++)
- {
- pStmt = con
- .prepareStatement("INSERT INTO views_graphs VALUES("
- + view_id + "," + graphsArray[i] + ")");
- pStmt.executeUpdate();
- }
+ for (int i = 0; i < graphsArray.length; i++) {
+ pStmt = con.prepareStatement("INSERT INTO views_graphs VALUES("
+ + view_id + "," + graphsArray[i] + ")");
+ pStmt.executeUpdate();
+ }
}
con.close();
actionResponse.setRenderParameter("message",
"<font color=\"green\"><strong><li>View " + name
+ " has been added</li></strong></font>");
- return;
-
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
actionResponse.setRenderParameter("message",
"<font color=\"red\"><strong><li>Error adding View " + name
+ "</li></strong></font>" + e.getMessage());
- return;
+ } finally {
+ try {
+ con.close();
+ } catch(Exception e) {
+
+ }
}
}
@@ -674,13 +675,13 @@
String snapshot = actionRequest.getParameter("snapshot");
String retention = actionRequest.getParameter("retention");
// encrypt the password
- password = EncryptionManager.encrypt(password);
+ if(password != null && !password.equals("")) {
+ password = EncryptionManager.encrypt(password);
+ }
- try
- {
+ try {
// update the client side db (table = SERVERS)
- if (password.equals(""))
- {
+ if (password.equals("") || password == null) {
PreparedStatement pStmt = con
.prepareStatement("UPDATE servers SET name='"
+ name
@@ -691,9 +692,19 @@
+ "', modified=CURRENT_TIMESTAMP, last_seen=CURRENT_TIMESTAMP WHERE server_id="
+ server_id);
pStmt.executeUpdate();
- }
- else
- {
+ // when user did not specify the password, just grab it from the db
+ pStmt = con.prepareStatement("SELECT password FROM servers WHERE server_id=" + server_id);
+ ResultSet s = pStmt.executeQuery();
+ if(s.next()) {
+ password = s.getString("password");
+ } else {
+ actionResponse.setRenderParameter("message",
+ "<font color=\"red\"><strong><li>Error updating server</li></strong></font>"
+ + "Password was not found in the database for server_id=" + server_id);
+ con.close();
+ return;
+ }
+ } else {
PreparedStatement pStmt = con
.prepareStatement("UPDATE servers SET name='"
+ name
@@ -709,17 +720,17 @@
}
con.close();
// update the server side db
- (new MRCConnector(ip, username, password)).setSnapshotDuration(Long
- .parseLong(snapshot) * 1000 * 60);
- (new MRCConnector(ip, username, password)).setSnapshotRetention(Integer.parseInt(retention));
+ if(snapshot == null || retention == null) {
+ // do not update if we do not know
+ } else {
+ (new MRCConnector(ip, username, password)).setSnapshotDuration(Long.parseLong(snapshot) * 1000 * 60);
+ (new MRCConnector(ip, username, password)).setSnapshotRetention(Integer.parseInt(retention));
+ }
// set success message
- actionResponse
- .setRenderParameter(
+ actionResponse.setRenderParameter(
"message",
"<font color=\"green\"><strong><li>Server has been updated</li></strong></font>");
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
actionResponse.setRenderParameter("message",
"<font color=\"red\"><strong><li>Error updating server</li></strong></font>"
+ e.getMessage());
@@ -736,7 +747,9 @@
String password = actionRequest.getParameter("password");
String username = actionRequest.getParameter("username");
// encrypt the password
- password = EncryptionManager.encrypt(password);
+ if(password != null && !password.equals("")) {
+ password = EncryptionManager.encrypt(password);
+ }
try
{
PreparedStatement pStmt = con
@@ -750,19 +763,20 @@
+ password
+ "',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)");
pStmt.executeUpdate();
- con.close();
actionResponse.setRenderParameter("message",
"<font color=\"green\"><strong><li>Server " + name + " at "
+ ip + " has been added.</li></strong></font>");
- return;
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
actionResponse.setRenderParameter("message",
"<font color=\"red\"><strong><li>Error adding server</li></strong></font>"
+ e.getMessage());
- return;
+ } finally {
+ try {
+ con.close();
+ } catch(Exception e) {
+
+ }
}
}
@@ -995,13 +1009,21 @@
try
{
- PreparedStatement pStmt = con
- .prepareStatement("DELETE FROM graphs WHERE graph_id="
- + graph_id);
+ // remove the graph
+ PreparedStatement pStmt = con.prepareStatement("DELETE FROM graphs WHERE graph_id=" + graph_id);
pStmt.executeUpdate();
- pStmt = con
- .prepareStatement("DELETE FROM views_graphs WHERE graph_id="
- + graph_id);
+ // fetch all views associated with this graph
+ pStmt = con.prepareStatement("SELECT view_id FROM views_graphs WHERE graph_id=" + graph_id);
+ ResultSet view_ids = pStmt.executeQuery();
+ // reduce the graph_count from all views associated with the graph
+ while(view_ids.next()) {
+ pStmt = con.prepareStatement(
+ "UPDATE views SET graph_count=graph_count-1 WHERE view_id="
+ + view_ids.getString("view_id"));
+ pStmt.executeUpdate();
+ }
+ // remove the relationship between graphs and views
+ pStmt = con.prepareStatement("DELETE FROM views_graphs WHERE graph_id=" + graph_id);
pStmt.executeUpdate();
con.close();
actionResponse
Modified: geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp?rev=601520&r1=601519&r2=601520&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp (original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditServer.jsp Wed Dec 5 12:57:32 2007
@@ -77,6 +77,7 @@
String modified = "";
String last_seen = "";
boolean enabled = true;
+String dbPassword = "";
if (rs.next()) {
// name == "" when user has not submitted anything
@@ -85,7 +86,7 @@
name = rs.getString("name");
username = rs.getString("username");
ip = rs.getString("ip");
- password = (String)EncryptionManager.decrypt( rs.getString("password") );
+ dbPassword = (String)EncryptionManager.decrypt(rs.getString("password"));
}
added = rs.getString("added");
modified = rs.getString("modified");
@@ -95,18 +96,20 @@
// close connection before using the MRCConnector
con.close();
mrc = new MRCConnector(ip, username, password);
- // get the snapshot on the first call or any subsequent valid connections
- snapshot = snapshot == "" ? "" + mrc.getSnapshotDuration() / 1000 / 60 : snapshot;
- // get the retention on the first call or any subsequent valid connection
- retention = retention == "" ? "" + mrc.getSnapshotRetention() : retention;
} catch (Exception e) {
- // TODO:
- // to know if the server is online/offline, we need to give the correct credentials
- // then we will know if it's truely online/offline. So this should not be done in this
- // catch block.
-
- //isOnline = false;
- //message = message + "<br><font color='red'><li>Server is offline</li></font>";
+ // the password supplied by the user doesn't work
+ try {
+ if(retention.equals("") || snapshot.equals("")) {
+ mrc = new MRCConnector(ip, username, dbPassword);
+ // get the snapshot on the first call or any subsequent valid connections
+ snapshot = snapshot == "" ? "" + mrc.getSnapshotDuration() / 1000 / 60 : snapshot;
+ // get the retention on the first call or any subsequent valid connection
+ retention = retention == "" ? "" + mrc.getSnapshotRetention() : retention;
+ }
+ } catch(Exception ee) {
+ // the password in the db does not work
+ isOnline = false;
+ }
}
%>
<!-- <head> -->
@@ -127,10 +130,27 @@
if (! (document.editServer.name.value
&& document.editServer.ip.value
&& document.editServer.username.value
+ && document.editServer.snapshot.value ))
+ {
+ alert("Name, Address, Username, and Snapshot Duration are all required fields.");
+ return false;
+ }
+ if (document.editServer.password.value != document.editServer.password2.value)
+ {
+ alert("Passwords do not match");
+ return false;
+ }
+ return true;
+}
+
+function validateTest() {
+ if (! (document.editServer.name.value
+ && document.editServer.ip.value
+ && document.editServer.username.value
&& document.editServer.snapshot.value
&& document.editServer.password.value ))
{
- alert("Name, Address, Username, Snapshot Duration, and Password are all required fields.");
+ alert("Name, Address, Username, and Snapshot Duration are all required fields.");
return false;
}
if (document.editServer.password.value != document.editServer.password2.value)
@@ -140,6 +160,7 @@
}
return true;
}
+
function noAlpha(obj){
reg = /[^0-9]/g;
obj.value = obj.value.replace(reg,"");
@@ -230,7 +251,7 @@
<tr>
<td>Snapshot Retention:</td>
<td> </td>
- <td align="right"><input type="text" width="5" size="4" name="retention" onKeyUp='noAlpha(this)' onKeyPress='noAlpha(this)' value="<%=retention%>"/></td>
+ <td align="right"><input type="text" width="5" size="4" name="retention" onKeyUp='noAlpha(this)' onKeyPress='noAlpha(this)' disabled="disabled" value="unknown"/></td>
<td> days</td>
</tr>
@@ -286,7 +307,7 @@
<td bgcolor="#FFFFFF" nowrap>
<br />
<ul>
- <li><a onclick="document.editServer.action.value='testEditServerConnection'; document.editServer.mode.value='edit'; if(validate()) document.editServer.submit();" href="#">Test these settings</a></li>
+ <li><a onclick="document.editServer.action.value='testEditServerConnection'; document.editServer.mode.value='edit'; if(validateTest()) document.editServer.submit();" href="#">Test these settings</a></li>
<%
if(enabled) {
%>
Modified: geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditView.jsp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditView.jsp?rev=601520&r1=601519&r2=601520&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditView.jsp (original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringEditView.jsp Wed Dec 5 12:57:32 2007
@@ -208,7 +208,6 @@
<ul>
<li><a href="<portlet:actionURL portletMode="view"><portlet:param name="action" value="showView" /><portlet:param name="view_id" value="<%=view_id%>" /></portlet:actionURL>">Show this view</a></li>
<li><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="showAddGraph" /></portlet:actionURL>">Create a new graph</a></li>
- <li><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="disableView" /><portlet:param name="view_id" value="<%=view_id%>" /></portlet:actionURL>">Disable this view</a></li>
<li><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="deleteView" /><portlet:param name="view_id" value="<%=view_id%>" /></portlet:actionURL>">Delete this view</a></li>
<li><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="showAddView" /></portlet:actionURL>">Add a new view</a></li>
</ul>