geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecr...@apache.org
Subject svn commit: r598765 - in /geronimo/sandbox/monitoring/client/client-war/src/main: java/org/apache/geronimo/plugins/monitoring/client/ java/org/apache/geronimo/plugins/monitoring/client/util/ webapp/WEB-INF/view/
Date Tue, 27 Nov 2007 21:02:46 GMT
Author: ecraig
Date: Tue Nov 27 13:02:44 2007
New Revision: 598765

URL: http://svn.apache.org/viewvc?rev=598765&view=rev
Log:
Monitoring client
GERONIMO-3635 patch from Viet applied with some modifications
to make things a bit more human-readable / user friendly

Modified:
    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/java/org/apache/geronimo/plugins/monitoring/client/util/DBManager.java
    geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp
    geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp

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=598765&r1=598764&r2=598765&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
Tue Nov 27 13:02:44 2007
@@ -21,6 +21,7 @@
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
@@ -57,12 +58,6 @@
 
     private static final String      ADDSERVER_JSP      = "/WEB-INF/view/monitoringAddServer.jsp";
 
-    private static final String      MBEAN_JSP          = "/WEB-INF/view/monitoringMbean.jsp";
-
-    private static final String      TIMEFRAME_JSP      = "/WEB-INF/view/monitoringTimeframe.jsp";
-
-    private static final String      MAXIMIZEDVIEW_JSP  = "/WEB-INF/view/monitoringMaximized.jsp";
-
     private static final String      HELPVIEW_JSP       = "/WEB-INF/view/monitoringHelp.jsp";
 
     private static final String      EDITNORMALVIEW_JSP = "/WEB-INF/view/monitoringEdit.jsp";
@@ -85,12 +80,6 @@
 
     private PortletRequestDispatcher addServer;
 
-    private PortletRequestDispatcher mBeanView;
-
-    private PortletRequestDispatcher timeFrameView;
-
-    private PortletRequestDispatcher maximizedView;
-
     private PortletRequestDispatcher helpView;
 
     private PortletRequestDispatcher editNormalView;
@@ -117,7 +106,7 @@
         }
         else if (action.equals("showAddView"))
         {
-
+            // no parameters needed to be redirected to doView()
         }
         else if (action.equals("saveAddView"))
         {
@@ -174,7 +163,7 @@
         }
         else if (action.equals("showAddServer"))
         {
-
+            // no parameters needed to be redirected to doView()
         }
         else if (action.equals("deleteServer"))
         {
@@ -212,6 +201,78 @@
             actionResponse.setRenderParameter("snapshotDuration",
                     snapshotDuration);
         }
+        else if (action.equals("disableServer"))
+        {
+            String server_id = actionRequest.getParameter("server_id");
+            actionResponse.setRenderParameter("message", alterServerState(
+                    server_id, false));
+        }
+        else if (action.equals("enableServer"))
+        {
+            String server_id = actionRequest.getParameter("server_id");
+            actionResponse.setRenderParameter("message", alterServerState(
+                    server_id, true));
+        }
+    }
+
+    private String alterServerState(String server_id, boolean b)
+    {
+        Connection conn = (new DBManager()).getConnection();
+        String message = "";
+        String name = "";
+        try
+        {
+            PreparedStatement pStmt = conn
+                    .prepareStatement("SELECT * FROM servers WHERE server_id="
+                            + server_id);
+            ResultSet rs = pStmt.executeQuery();
+            if (rs.next())
+            {
+                name = rs.getString("name");
+            }
+            rs.close();
+            conn.close();
+            conn = (new DBManager()).getConnection();
+            Statement stmt = conn.createStatement();
+            if (!b)
+            {
+                stmt
+                        .executeUpdate("UPDATE SERVERS SET ENABLED = 0 WHERE SERVER_ID="
+                                + server_id);
+                message = "Server " + name + " was successfully disabled.";
+            }
+            else
+            {
+                stmt
+                        .executeUpdate("UPDATE SERVERS SET ENABLED = 1 WHERE SERVER_ID="
+                                + server_id);
+                message = "Server " + name + " was successfully enabled.";
+            }
+        }
+        catch (SQLException e)
+        {
+            if (!b)
+                message = "[ERROR] Server with server_id = " + server_id
+                        + " could not be disabled.";
+            else
+                message = "[ERROR] Server with server_id = " + server_id
+                        + " could not be enabled.";
+        }
+        finally
+        {
+            if (conn != null)
+            {
+                try
+                {
+                    conn.close();
+                }
+                catch (Exception e)
+                {
+
+                }
+            }
+        }
+        return message;
     }
 
     @Override
@@ -584,6 +645,7 @@
         }
         else
         {
+            request.setAttribute("message", request.getParameter("message"));
             normalView.include(request, response);
         }
 
@@ -701,7 +763,7 @@
             editNormalView.include(request, response);
     }
 
-    protected void updateView(ActionRequest actionRequest,
+    private void updateView(ActionRequest actionRequest,
             ActionResponse actionResponse)
     {
         String view_id = actionRequest.getParameter("view_id");
@@ -748,7 +810,7 @@
         }
     }
 
-    protected void addView(ActionRequest actionRequest,
+    private void addView(ActionRequest actionRequest,
             ActionResponse actionResponse)
     {
         DBManager DBase = new DBManager();
@@ -799,7 +861,7 @@
         }
     }
 
-    protected void updateServer(ActionRequest actionRequest,
+    private void updateServer(ActionRequest actionRequest,
             ActionResponse actionResponse)
     {
         String server_id = actionRequest.getParameter("server_id");
@@ -810,7 +872,6 @@
         String ip = actionRequest.getParameter("ip");
         String password = actionRequest.getParameter("password");
         String username = actionRequest.getParameter("username");
-        String snapshot = actionRequest.getParameter("snapshot");
         try
         {
             if (password.equals(""))
@@ -858,7 +919,7 @@
         }
     }
 
-    protected void addServer(ActionRequest actionRequest,
+    private void addServer(ActionRequest actionRequest,
             ActionResponse actionResponse)
     {
         DBManager DBase = new DBManager();
@@ -896,7 +957,7 @@
         }
     }
 
-    protected void deleteServer(ActionRequest actionRequest,
+    private void deleteServer(ActionRequest actionRequest,
             ActionResponse actionResponse)
     {
         String server_id = actionRequest.getParameter("server_id");
@@ -931,7 +992,7 @@
         }
     }
 
-    protected void deleteView(ActionRequest actionRequest,
+    private void deleteView(ActionRequest actionRequest,
             ActionResponse actionResponse)
     {
         String view_id = actionRequest.getParameter("view_id");
@@ -965,7 +1026,7 @@
         }
     }
 
-    protected void addGraph(ActionRequest actionRequest,
+    private void addGraph(ActionRequest actionRequest,
             ActionResponse actionResponse)
     {
         DBManager DBase = new DBManager();
@@ -1033,7 +1094,7 @@
         }
     }
 
-    protected void updateGraph(ActionRequest actionRequest,
+    private void updateGraph(ActionRequest actionRequest,
             ActionResponse actionResponse)
     {
         DBManager DBase = new DBManager();
@@ -1105,7 +1166,7 @@
         }
     }
 
-    protected void deleteGraph(ActionRequest actionRequest,
+    private void deleteGraph(ActionRequest actionRequest,
             ActionResponse actionResponse)
     {
         String graph_id = actionRequest.getParameter("graph_id");
@@ -1161,12 +1222,6 @@
                 EDITSERVER_JSP);
         addServer = portletConfig.getPortletContext().getRequestDispatcher(
                 ADDSERVER_JSP);
-        mBeanView = portletConfig.getPortletContext().getRequestDispatcher(
-                MBEAN_JSP);
-        timeFrameView = portletConfig.getPortletContext().getRequestDispatcher(
-                TIMEFRAME_JSP);
-        maximizedView = portletConfig.getPortletContext().getRequestDispatcher(
-                MAXIMIZEDVIEW_JSP);
         helpView = portletConfig.getPortletContext().getRequestDispatcher(
                 HELPVIEW_JSP);
         editNormalView = portletConfig.getPortletContext()
@@ -1185,9 +1240,6 @@
         viewServer = null;
         editServer = null;
         addServer = null;
-        mBeanView = null;
-        timeFrameView = null;
-        maximizedView = null;
         helpView = null;
         editNormalView = null;
         super.destroy();

Modified: geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/util/DBManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/util/DBManager.java?rev=598765&r1=598764&r2=598765&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/util/DBManager.java
(original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/util/DBManager.java
Tue Nov 27 13:02:44 2007
@@ -24,8 +24,6 @@
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
-import javax.naming.NameClassPair;
-import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
 
@@ -48,7 +46,8 @@
         try
         {
             Context context = new InitialContext();
-            DataSource ds = (DataSource) context.lookup("java:comp/env/MonitoringClientDS");
+            DataSource ds = (DataSource) context
+                    .lookup("java:comp/env/MonitoringClientDS");
             con = ds.getConnection();
         }
         catch (NamingException e)

Modified: geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp?rev=598765&r1=598764&r2=598765&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp
(original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp
Tue Nov 27 13:02:44 2007
@@ -1,3 +1,4 @@
+
 <%--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -26,12 +27,12 @@
 <%@ page import="org.apache.geronimo.console.util.PortletManager" %>
 <portlet:defineObjects/>
 <%
- String message = (String) request.getAttribute("message"); 
- if (message != null)
- {
- %>
-<p><%=message %></p>
-<%} %>
+    String message = (String) request.getAttribute("message"); 
+    if (message != null)
+    {
+%>
+        <p><%= message %></p>
+<%  } %>
 <br>
 <table width="100%" style="border-style: solid;
 border-width: 1px;">
@@ -47,7 +48,7 @@
  DBManager DBase = new DBManager();
  Connection con = DBase.getConnection();
  
- PreparedStatement pStmt = con.prepareStatement("SELECT view_id, name, description, graph_count,
added, modified FROM views WHERE enabled=1");
+ PreparedStatement pStmt = con.prepareStatement("SELECT view_id, name, description, graph_count,
added, modified FROM views");
  ResultSet rs = pStmt.executeQuery();
  while (rs.next())
  {
@@ -85,15 +86,18 @@
  </tr>
  <%
  
- pStmt = con.prepareStatement("SELECT * FROM servers WHERE enabled=1");
+ pStmt = con.prepareStatement("SELECT * FROM servers");
  rs = pStmt.executeQuery();
  con.close();
  while (rs.next())
  {
      boolean online = false;
      boolean collecting = false;
+     boolean enabled = rs.getInt("enabled") == 1 ? true : false;
      MRCConnector MRCConnection = null;
      Long snapshotDuration = new Long(0);
+     if (enabled)
+     {
      try 
      {
          MRCConnection = new MRCConnector(rs.getString("ip"), rs
@@ -117,11 +121,7 @@
          collecting = false;
          online = false;
      }
-     
-//     String server_name = rs.getString("server_name");
-//     String server_ip = rs.getString("server_ip");
-//     String username = rs.getString("username");
-//     String password = rs.getString("password");
+     }
 
  %>
   <c:set var="backgroundClass" value='MediumBackground'/>
@@ -134,35 +134,73 @@
       </c:otherwise>
   </c:choose>
  <tr>
+ <%
+if(enabled){
+ %>
   <td class="${backgroundClass}" width="30%" align="center"><a href="<portlet:actionURL
portletMode="view"><portlet:param name="action" value="showServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>"><%=rs.getString("name")%></a></td>
   <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="view"><portlet:param name="action" value="showServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>"><%=rs.getString("ip")%></a></td>
 <%
-if (online && collecting)
-{
+}
+else{
+    %>
+    <td class="${backgroundClass}" width="30%" align="center"><%=rs.getString("name")%></td>
+    <td class="${backgroundClass}" width="10%" align="center"><%=rs.getString("ip")%></td>
+  <% 
+}
+if (online) {     // online
 %>
   <td class="${backgroundClass}" width="15%" align="center" bgcolor="#cccccc">Online</td>
+<%
+} else if(enabled){         // offline
+%>
+  <td class="${backgroundClass}" width="15%" align="center"><font color="red">Offline</font></td>
+<%
+} else {         // Disabled
+     %>
+       <td class="${backgroundClass}" width="15%" align="center"><font color="red">Disabled</font></td>
+     <%
+     }
+if (!collecting) {  // not collecting statistics
+%>
+    <td class="${backgroundClass}" width="15%" align="center"><font color="red">(stopped)</font></td>
+<%
+    if(enabled) {   // enable the links
+%>
+        <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="view"><portlet:param name="action" value="startThread" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /><portlet:param name="snapshotDuration"
value="<%=java.lang.Long.toString(snapshotDuration)%>" /></portlet:actionURL>">Enable
Query</a></td>
+<%
+    } else {        // do not provide links
+%>
+        <td class="${backgroundClass}" width="10%" align="center">Enable Query</td>
+<%
+    }
+%>
+  <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="showEditServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Edit</a></td>
+<%
+} else {            // collecting statistics
+    if (enabled)
+    {
+%>
   <td class="${backgroundClass}" width="15%" align="center"><%=snapshotDuration/1000/60+"
min. (running)"%></td>
   <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="view"><portlet:param name="action" value="stopThread" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Disable
Query</a></td>
   <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="showEditServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Edit</a></td>
-  <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="disableServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Disable</a></td>
 <%
+    }
+    else
+    {
+        %>
+        <td class="${backgroundClass}" width="15%" align="center">Stopped</td>
+        <td class="${backgroundClass}" width="10%" align="center">Disable Query</td>
+        <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="showEditServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Edit</a></td>
+      <%        
+    }
 }
-else if (online && !collecting)
-{%>
-  <td class="${backgroundClass}" width="15%" align="center" bgcolor="#cccccc">Online</td>
-  <td class="${backgroundClass}" width="15%" align="center" bgcolor="red"><%=snapshotDuration/1000/60+"
min. (stopped)"%></td>
-  <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="view"><portlet:param name="action" value="startThread" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /><portlet:param name="snapshotDuration"
value="<%=java.lang.Long.toString(snapshotDuration)%>" /></portlet:actionURL>">Enable
Query</a></td>
-  <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="showEditServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Edit</a></td>
-  <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="disableServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Disable</a></td>
+if(enabled) {   // enabled server
+%>
+  <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="view"><portlet:param name="action" value="disableServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Disable</a></td>
 <%
-}
-else if (!online)
-{%>
-<td class="${backgroundClass}" width="15%" align="center"><font color="red">Offline</font></td>
-<td class="${backgroundClass}" width="15%" align="center"><font color="red">(stopped)</font></td>
-<td class="${backgroundClass}" width="10%" align="center">Enable Query</td>
-<td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="showEditServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Edit</a></td>
-<td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="edit"><portlet:param name="action" value="disableServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Disable</a></td>
+} else {        // disabled server
+%>
+  <td class="${backgroundClass}" width="10%" align="center"><a href="<portlet:actionURL
portletMode="view"><portlet:param name="action" value="enableServer" /><portlet:param
name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Enable</a></td>
 <%
 }
 %>

Modified: geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp?rev=598765&r1=598764&r2=598765&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp
(original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp
Tue Nov 27 13:02:44 2007
@@ -46,15 +46,14 @@
     pStmt = con.prepareStatement("SELECT * FROM views_graphs WHERE view_id="+view_id);
     ResultSet rs2 = pStmt.executeQuery();
 
-    Vector <StatsGraph> GraphVector = new Vector<StatsGraph>();
-    while (rs2.next())
-    {
-        try
-        {
-        GraphVector.add(run.buildOneDB(14, rs2.getInt("graph_id")));
-        }
-        catch (Exception e)
-        {
+    Vector <StatsGraph> graphs = new Vector<StatsGraph>();
+    while (rs2.next()) {
+        try {
+            StatsGraph graph = run.buildOneDB(14, rs2.getInt("graph_id"));
+            if(graph != null) {
+                graphs.add( graph );
+            }
+        } catch (Exception e) {
             errors = errors + "<li>Graph "+rs2.getInt("graph_id")+" could not be drawn
due to server being offline</li>";
         }
     }
@@ -65,7 +64,7 @@
     <% 
     try
     {
-    for (StatsGraph graph : GraphVector) 
+    for (StatsGraph graph : graphs) 
             out.println(graph.getDiv());
     }
     catch (Exception e)
@@ -94,7 +93,7 @@
     dojo.require("dojo.collections.Store");
     dojo.require("dojo.charting.Chart");
     dojo.require('dojo.json');
-    <% for (StatsGraph graph : GraphVector)
+    <% for (StatsGraph graph : graphs)
        out.println(graph.getJS());
 
     %>
@@ -116,7 +115,7 @@
 <% 
 try
 {
-for (StatsGraph graph : GraphVector) 
+for (StatsGraph graph : graphs) 
 {
 %>
 <p>



Mime
View raw message