geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecr...@apache.org
Subject svn commit: r599235 - in /geronimo/sandbox/monitoring/client/client-war/src/main: java/org/apache/geronimo/plugins/monitoring/client/ webapp/WEB-INF/view/
Date Thu, 29 Nov 2007 01:07:00 GMT
Author: ecraig
Date: Wed Nov 28 17:06:58 2007
New Revision: 599235

URL: http://svn.apache.org/viewvc?rev=599235&view=rev
Log:
Monitoring client should update last_seen value in database for both 
server and graph whenever they are successfully accessed/generated.

Applied GERONIMO-3646 patch by Viet Nguyen


Modified:
    geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java
    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/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/GraphsBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java?rev=599235&r1=599234&r2=599235&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java (original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java Wed Nov 28 17:06:58 2007
@@ -19,201 +19,192 @@
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.text.DecimalFormat;
+import java.text.Format;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.TreeMap;
 import java.util.Vector;
 
+import org.apache.geronimo.plugins.monitoring.client.util.DBManager;
+
 public class GraphsBuilder
 {
-    private String           ServerIP      = new String();
+    private String           ip      = new String();
     private int              timeFrame;
     private int              snapCount;
-    private MRCConnector     MRCConnection = new MRCConnector();
-    private final Connection Con;
+    private MRCConnector     mrc = new MRCConnector();
+    private Connection con;
 
     // constructor
     public GraphsBuilder(Connection con)
     {
         // TODO: Database pull stuff may go here... based on server ID...\
-        Con = con;
-
+        this.con = con;
     }
 
-    public StatsGraph buildOneDB(int graph_id) throws Exception
-    {
+    public StatsGraph buildOneDB(int graph_id) throws Exception {
+        con = (new DBManager()).getConnection();
+        StatsGraph graph = null;
         PreparedStatement pStmt = null;
         ResultSet rsServer = null;
-        pStmt = Con
-                .prepareStatement("SELECT * from graphs WHERE enabled=1 AND graph_id="
-                        + graph_id);
+        pStmt = con.prepareStatement("SELECT * from graphs WHERE enabled=1 AND graph_id=" + graph_id);
         ResultSet rs = pStmt.executeQuery();
-
-        if (rs.next())
-        {
-            pStmt = Con
-                    .prepareStatement("SELECT * from servers WHERE enabled=1 AND server_id="
-                            + rs.getInt("server_id"));
-            rsServer = pStmt.executeQuery();
-
-            if (rsServer.next())
-            {
-                ServerIP = rsServer.getString("ip");
-
-                MRCConnection = new MRCConnector(ServerIP, rsServer
-                        .getString("username"), rsServer.getString("password"));
-            }
-            else
-                return null;
-
+        if (rs.next()) {
             String mBeanName = rs.getString("mbean");
             String dataName1 = rs.getString("dataname1");
             String dataName2 = rs.getString("dataname2");
             String graphName1 = rs.getString("dataname1");
             String graphName2 = rs.getString("dataname2");
             timeFrame = rs.getInt("timeframe");
-
-            snapCount = timeFrame
-                    / java.lang.Integer
-                            .valueOf(java.lang.Long.toString((MRCConnector
-                                    .getSnapshotDuration() / new Long(60000))));
-            HashMap<String, Vector<Object>> DataList = new HashMap<String, Vector<Object>>();
-
-            DataList.put(graphName1, new Vector<Object>());
-            if (!dataName2.equals("time") && (dataName2 != null)
-                    && !dataName2.equals("null") && !dataName2.equals(""))
-            {
-                DataList.put(graphName2, new Vector<Object>());
-            }
-            if ((timeFrame / 1440 >= 30))
-                snapCount = 17;
-            else
-            {
-                if (((timeFrame / 1440) <= 7) && ((timeFrame / 60) > 24)
-                        && snapCount >= 14)
-                {
-                    if ((timeFrame / 1440) == 7)
-                        snapCount = 16;
+            String server_id = rs.getString("server_id");
+            String xlabel = rs.getString("xlabel");
+            String ylabel = rs.getString("ylabel");
+            String data1operation = rs.getString("data1operation");
+            String data2operation = rs.getString("data2operation");
+            String operation = rs.getString("operation");
+            String color = rs.getString("color");
+            float warninglevel1 = rs.getFloat("warninglevel1");
+            String description = rs.getString("description");
+            
+            pStmt = con.prepareStatement("SELECT * from servers WHERE enabled=1 AND server_id=" + server_id);
+            rsServer = pStmt.executeQuery();
+            if (rsServer.next()) {
+                ip = rsServer.getString("ip");
+                String username = rsServer.getString("username");
+                String password = rsServer.getString("password");
+                // close the connection before calling the MRCConnector because it opens another
+                // connection to the db to update the SERVERS.last_seen attribute
+                try {
+                    con.close();
+                } catch(Exception e) {
+                    throw e;
                 }
-            }
-
-            Vector<Object> snapshot_time = new Vector<Object>();
+                mrc = new MRCConnector(ip, username, password);
 
-            Vector<Object> PrettyTime = new Vector<Object>();
+                snapCount = timeFrame
+                        / java.lang.Integer
+                                .valueOf(java.lang.Long.toString((mrc.getSnapshotDuration() / new Long(60000))));
+                HashMap<String, Vector<Object>> DataList = new HashMap<String, Vector<Object>>();
 
-            String prettyTimeFrame = new String();
-            DecimalFormat fmt = new DecimalFormat("0.##");
-            if (timeFrame / 60 > 24)
-                prettyTimeFrame = fmt.format((float) (timeFrame / 1440))
-                        + " day";
-            else
-            {
-                if (timeFrame > 60)
-                    prettyTimeFrame = fmt.format((float) timeFrame / 60)
-                            + " hour";
+                DataList.put(graphName1, new Vector<Object>());
+                if (!dataName2.equals("time") && (dataName2 != null)
+                        && !dataName2.equals("null") && !dataName2.equals(""))
+                {
+                    DataList.put(graphName2, new Vector<Object>());
+                }
+                if ((timeFrame / 1440 >= 30))
+                    snapCount = 17;
                 else
-                    prettyTimeFrame = fmt.format(timeFrame) + " minute";
-            }
-
-            int skipCount = (int) ((timeFrame / (MRCConnector
-                    .getSnapshotDuration() / 60000)))
-                    / (snapCount - 2);
-            snapCount = snapCount + 2;
-            TreeMap<Long, Long> snapshotList = MRCConnection
-                    .getSpecificStatistics(mBeanName, dataName1, snapCount,
-                            skipCount);
-
-            // Check if snapshotList is empty
-
-            if (snapshotList.size() == 0)
-            {
-                snapshotList.put(System.currentTimeMillis(), new Long(0));
-
-                /*
-                 * If there are not enough snapshots available to fill the requested
-                 * number, insert some with values of 0 and the proper times.
-                 */
-                while (snapshotList.size() < snapCount)
                 {
-                    // Temporary, always is first element (oldest)
-                    Long timeFix = snapshotList.firstKey();
+                    if (((timeFrame / 1440) <= 7) && ((timeFrame / 60) > 24)
+                            && snapCount >= 14)
+                    {
+                        if ((timeFrame / 1440) == 7)
+                            snapCount = 16;
+                    }
+                }
 
-                    // Calculate appropriate time, add it to the submap,
-                    // then
-                    // add
-                    // that to the tempMap
-                    snapshotList.put((timeFix - (MRCConnector
-                            .getSnapshotDuration() * skipCount)), new Long(0));
+                Vector<Object> snapshot_time = new Vector<Object>();
+
+                Vector<Object> PrettyTime = new Vector<Object>();
+
+                String prettyTimeFrame = new String();
+                DecimalFormat fmt = new DecimalFormat("0.##");
+                if (timeFrame / 60 > 24) {
+                    prettyTimeFrame = fmt.format((float) (timeFrame / 1440)) + " day";
+                } else {
+                    if (timeFrame > 60) {
+                        prettyTimeFrame = fmt.format((float) timeFrame / 60) + " hour";
+                    } else {
+                        prettyTimeFrame = fmt.format(timeFrame) + " minute";
+                    }
                 }
-            }
 
-            for (Iterator<Long> it = snapshotList.keySet().iterator(); it
-                    .hasNext();)
-            {
-                Long current = it.next();
-                snapshot_time.add(current);
-                Vector<Object> vectorTemp = DataList.get(graphName1);
-                vectorTemp.add(snapshotList.get(current));
-                DataList.put(graphName1, vectorTemp);
-                if (!dataName2.equals("time") && (dataName2 != null)
-                        && !dataName2.equals("null") && !dataName2.equals(""))
-                {
-                    Vector<Object> vectorTemp2 = DataList.get(graphName2);
-                    vectorTemp2.add(snapshotList.get(current));
-                    DataList.put(graphName2, vectorTemp2);
+                int skipCount = (int) ((timeFrame / (mrc.getSnapshotDuration() / 60000))) / (snapCount - 2);
+                snapCount = snapCount + 2;
+                TreeMap<Long, Long> snapshotList = mrc
+                        .getSpecificStatistics(mBeanName, dataName1, snapCount, skipCount);
+
+                // Check if snapshotList is empty
+                if (snapshotList.size() == 0) {
+                    snapshotList.put(System.currentTimeMillis(), new Long(0));
+                    /*
+                     * If there are not enough snapshots available to fill the requested
+                     * number, insert some with values of 0 and the proper times.
+                     */
+                    while (snapshotList.size() < snapCount) {
+                        // Temporary, always is first element (oldest)
+                        Long timeFix = snapshotList.firstKey();
+                        // Calculate appropriate time, add it to the submap,
+                        // then
+                        // add
+                        // that to the tempMap
+                        snapshotList.put((timeFix - (mrc.getSnapshotDuration() * skipCount)), new Long(0));
+                    }
                 }
 
-                PrettyTime.add((Long) current / 1000);
-            }
+                for (Iterator<Long> it = snapshotList.keySet().iterator(); it.hasNext(); ) {
+                    Long current = it.next();
+                    snapshot_time.add(current);
+                    Vector<Object> vectorTemp = DataList.get(graphName1);
+                    vectorTemp.add(snapshotList.get(current));
+                    DataList.put(graphName1, vectorTemp);
+                    if (!dataName2.equals("time") && (dataName2 != null)
+                            && !dataName2.equals("null") && !dataName2.equals("")) {
+                        Vector<Object> vectorTemp2 = DataList.get(graphName2);
+                        vectorTemp2.add(snapshotList.get(current));
+                        DataList.put(graphName2, vectorTemp2);
+                    }
+                    PrettyTime.add((Long) current / 1000);
+                }
 
-            if (dataName2.equals("time"))
-                return (new StatsGraph(graph_id, ServerIP + " - "
-                        + rs.getString("xlabel") + " - " + prettyTimeFrame, rs
-                        .getString("description"), "Time - " + prettyTimeFrame,
-                        rs.getString("ylabel"), rs.getString("data1operation")
-                                .charAt(0), DataList.get(graphName1), rs
-                                .getString("operation"), rs.getString(
-                                "data2operation").charAt(0), PrettyTime,
-                        snapshot_time, (int) (MRCConnector
-                                .getSnapshotDuration() / 1000), timeFrame, rs
-                                .getString("color"), rs
-                                .getFloat("warninglevel1"), rs
-                                .getFloat("warninglevel1")));
-            else if (!dataName2.equals("time") && (dataName2 != null)
-                    && !dataName2.equals("null") && !dataName2.equals(""))
-                return (new StatsGraph(graph_id, ServerIP + " - "
-                        + rs.getString("xlabel") + " - " + prettyTimeFrame, rs
-                        .getString("description"), "Time - " + prettyTimeFrame,
-                        rs.getString("ylabel"), rs.getString("data1operation")
-                                .charAt(0), DataList.get(graphName1), rs
-                                .getString("operation"), rs.getString(
-                                "data2operation").charAt(0), DataList
-                                .get(graphName2), snapshot_time,
-                        (int) (MRCConnector.getSnapshotDuration() / 1000),
-                        timeFrame, rs.getString("color"), rs
-                                .getFloat("warninglevel1"), rs
-                                .getFloat("warninglevel1")));
-            else if (dataName2 == null || dataName2.equals("null")
-                    || dataName2.equals(""))
-            {
-                return (new StatsGraph(graph_id, ServerIP + " - "
-                        + rs.getString("xlabel") + " - " + prettyTimeFrame, rs
-                        .getString("description"), "Time - " + prettyTimeFrame,
-                        rs.getString("ylabel"), rs.getString("data1operation")
-                                .charAt(0), DataList.get(graphName1), rs
-                                .getString("operation"), snapshot_time,
-                        (int) (MRCConnector.getSnapshotDuration() / 1000),
-                        timeFrame, rs.getString("color"), rs
-                                .getFloat("warninglevel1"), rs
-                                .getFloat("warninglevel1")));
+                if (dataName2.equals("time")) {
+                    graph = (new StatsGraph(graph_id, ip + " - "
+                            + xlabel + " - " + prettyTimeFrame, description, "Time - " + prettyTimeFrame,
+                            ylabel, data1operation
+                                    .charAt(0), DataList.get(graphName1), operation, data2operation.charAt(0), PrettyTime,
+                            snapshot_time, (int) (mrc.getSnapshotDuration() / 1000), timeFrame, color, warninglevel1, warninglevel1));
+                } else if (!dataName2.equals("time") && (dataName2 != null)
+                        && !dataName2.equals("null") && !dataName2.equals("")) {
+                    graph = (new StatsGraph(graph_id, ip + " - "
+                            + xlabel + " - " + prettyTimeFrame, description, "Time - " + prettyTimeFrame,
+                            ylabel, data1operation.charAt(0), DataList.get(graphName1), operation, 
+                            data2operation.charAt(0), DataList
+                                    .get(graphName2), snapshot_time,
+                            (int) (mrc.getSnapshotDuration() / 1000),
+                            timeFrame, color, warninglevel1, warninglevel1));
+                } else if (dataName2 == null || dataName2.equals("null") || dataName2.equals("")) {
+                    graph = (new StatsGraph(graph_id, ip + " - "
+                            + xlabel + " - " + prettyTimeFrame, description, "Time - " + prettyTimeFrame,
+                            ylabel, data1operation.charAt(0), DataList.get(graphName1), operation, snapshot_time,
+                            (int) (mrc.getSnapshotDuration() / 1000),
+                            timeFrame, color, warninglevel1, warninglevel1));
+                } else {
+                    graph = (new StatsGraph());
+                }
             }
-            else
-                return (new StatsGraph());
         }
-
-        else
-            return null;
-
+        
+        // check to see if graph was successfully populated
+        if(graph != null) {
+            // get the current date
+            Format formatter = null;
+            formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            Date date = new Date(System.currentTimeMillis());
+            String currentTime = formatter.format(date);
+            // the graph was successfully operated on, 
+            // so update the last_seen attribute
+            DBManager dbManager = new DBManager();
+            Connection conn = dbManager.getConnection();
+            Statement stmt = conn.createStatement();
+            stmt.executeUpdate(
+                    "UPDATE GRAPHS SET LAST_SEEN='" + currentTime + "' WHERE GRAPH_ID=" + graph_id);
+            conn.close();
+        }
+        return graph;
     }
 }

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=599235&r1=599234&r2=599235&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 Nov 28 17:06:58 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.geronimo.plugins.monitoring.client;
 
+import java.sql.Connection;
+import java.sql.Statement;
 import java.text.Format;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -31,11 +33,12 @@
 import javax.naming.InitialContext;
 
 import org.apache.geronimo.monitor.MasterRemoteControlRemote;
+import org.apache.geronimo.plugins.monitoring.client.util.DBManager;
 
 public class MRCConnector
 {
 
-    private static MasterRemoteControlRemote mrc              = null;
+    private MasterRemoteControlRemote mrc              = null;
 
     MRCConnector()
     {
@@ -43,7 +46,7 @@
     }
 
     /**
-     * @param ServerIP -
+     * @param ip -
      *            IP address of mrc-server to connect to
      * @param userName -
      *            Username for JMX connection to the host
@@ -52,19 +55,42 @@
      * @throws Exception -
      *             If the connection to mrc-server fails
      */
-    public MRCConnector(String ServerIP, String userName, String password)
+    public MRCConnector(String ip, String userName, String password)
             throws Exception
     {
         Properties props = new Properties();
         props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                 "org.apache.openejb.client.RemoteInitialContextFactory");
-        props.setProperty(Context.PROVIDER_URL, "ejbd://" + ServerIP + ":4201");
+        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);
+        
+        // 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;
+        formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = new Date(System.currentTimeMillis());
+        String currentTime = formatter.format(date);
+        
+        Connection conn = DBManager.createConnection();
+        try {
+            Statement stmt = conn.createStatement();
+            stmt.executeUpdate("UPDATE SERVERS SET LAST_SEEN = '" + currentTime + "' WHERE IP='" + ip + "'");
+        } catch(Exception e) {
+            throw e;
+        } finally {
+            try {
+                if(conn != null){
+                    conn.close();
+                }
+            } catch(Exception e) {
+                
+            }
+        }
     }
 
     /**
@@ -73,7 +99,7 @@
      * @throws Exception -
      *             If the connection to the MRC-Server fails
      */
-    public static Long getSnapshotDuration() throws Exception
+    public Long getSnapshotDuration() throws Exception
     {
         return mrc.getSnapshotDuration();
     }
@@ -156,8 +182,7 @@
             // that to the tempMap
             subMap
                     .put("snapshot_time", ((Long) mapTimeFix.get("times").get(
-                            "snapshot_time") - (MRCConnector
-                            .getSnapshotDuration() * skipCount)));
+                            "snapshot_time") - (getSnapshotDuration() * skipCount)));
             Format formatter = null;
             formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             Date date = new Date((Long) subMap.get("snapshot_time"));
@@ -221,8 +246,7 @@
                 // here is where we will in missing data
                 while (((((Long) mapTimeFix.get("times").get("snapshot_time") / 1000) / 60)
                         - (((Long) mapTimeFix2.get("times")
-                                .get("snapshot_time") / 1000) / 60) > (((MRCConnector
-                        .getSnapshotDuration() / 1000) / 60) * skipCount)))
+                                .get("snapshot_time") / 1000) / 60) > (((getSnapshotDuration() / 1000) / 60) * skipCount)))
                 {
                     HashMap<String, HashMap<String, Object>> tempMap = new HashMap<String, HashMap<String, Object>>();
                     HashMap<String, Object> subMap = new HashMap<String, Object>();
@@ -260,8 +284,7 @@
                                     new Long(
                                             (Long) mapTimeFix.get("times").get(
                                                     "snapshot_time")
-                                                    - (MRCConnector
-                                                            .getSnapshotDuration() * skipCount)));
+                                                    - (getSnapshotDuration() * skipCount)));
                     Format formatter = null;
                     formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                     Date date = new Date((Long) subMap.get("snapshot_time"));
@@ -305,7 +328,7 @@
             // that to the tempMap
             snapshotList
                     .put(
-                            (timeFix - (MRCConnector.getSnapshotDuration() * skipCount)),
+                            (timeFix - (getSnapshotDuration() * skipCount)),
                             new Long(0));
         }
 
@@ -324,12 +347,11 @@
             Long tempLong2 = tempArray.get(i - 1);
             // here is where we will in missing data
             while (((((Long) tempLong1 / 1000) / 60)
-                    - (((Long) tempLong2 / 1000) / 60) > (((MRCConnector
-                    .getSnapshotDuration() / 1000) / 60) * skipCount)))
+                    - (((Long) tempLong2 / 1000) / 60) > (((getSnapshotDuration() / 1000) / 60) * skipCount)))
             {
 
                 tempLong1 = tempLong1
-                        - (MRCConnector.getSnapshotDuration() * skipCount);
+                        - (getSnapshotDuration() * skipCount);
                 snapshotList.put(tempLong1, new Long(0));
                 snapshotList.remove(tempArray.get(0));
                 tempArray.remove(0);
@@ -602,7 +624,7 @@
         return mrc.getStats(MBean);
     }
     
-    public static void setSnapshotDuration(long duration) {
+    public void setSnapshotDuration(long duration) {
         mrc.setSnapshotDuration(new Long(duration));
     }
 }

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=599235&r1=599234&r2=599235&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 Nov 28 17:06:58 2007
@@ -232,6 +232,7 @@
             String password = actionRequest.getParameter("password");
             String password2 = actionRequest.getParameter("password2");
             String server_id = actionRequest.getParameter("server_id");
+            String snapshot = actionRequest.getParameter("snapshot");
             String message = testConnection(name, ip, username, password);
             actionResponse.setRenderParameter("message", message);
             actionResponse.setRenderParameter("name", name);
@@ -239,6 +240,7 @@
             actionResponse.setRenderParameter("ip", ip);
             actionResponse.setRenderParameter("password", password);
             actionResponse.setRenderParameter("password2", password2);
+            actionResponse.setRenderParameter("snapshot", snapshot);
             actionResponse.setRenderParameter("server_id", server_id);
         }
     }
@@ -339,18 +341,16 @@
             request.setAttribute("mbean", mbean);
             PreparedStatement pStmt = null;
             ResultSet rs = null;
-            MRCConnector MRCConnection = null;
+            MRCConnector mrc = null;
             DBManager DBase = new DBManager();
             Connection con = DBase.getConnection();
             String server_ip = null;
-            try
-            {
-                pStmt = con
-                        .prepareStatement("SELECT * FROM servers WHERE server_id="
-                                + server_id);
+            String username = null;
+            String password = null;
+            try {               
+                pStmt = con.prepareStatement("SELECT * FROM servers WHERE server_id=" + server_id);
                 rs = pStmt.executeQuery();
-                if (!rs.next())
-                {
+                if (!rs.next()) {
                     request.setAttribute("message",
                             "<font color='red'>DATABASE ERROR: Server id "
                                     + server_id
@@ -358,20 +358,19 @@
                     viewServer.include(request, response);
                     return;
                 }
-            }
-            catch (SQLException e)
-            {
+                server_ip = rs.getString("ip");
+                password = rs.getString("password");
+                username = rs.getString("username");
+            } catch (SQLException e) {
                 request.setAttribute("message",
                         "<font color='red'>DATABASE ERROR: " + e.getMessage()
                                 + "</font>");
                 viewServer.include(request, response);
                 return;
             }
-            try
-            {
-                server_ip = rs.getString("ip");
-                MRCConnection = new MRCConnector(server_ip, rs
-                        .getString("username"), rs.getString("password"));
+            try {
+                con.close();
+                mrc = new MRCConnector(server_ip, username, password);
             }
             catch (Exception e)
             {
@@ -385,7 +384,7 @@
             }
             try
             {
-                if (MRCConnection.startTrackingMbean(mbean))
+                if (mrc.startTrackingMbean(mbean))
                 {
                     request.setAttribute("message", "<b>MBean " + mbean
                             + " tracking on server " + rs.getString("name")
@@ -425,18 +424,19 @@
             request.setAttribute("mbean", mbean);
             PreparedStatement pStmt = null;
             ResultSet rs = null;
-            MRCConnector MRCConnection = null;
+            MRCConnector mrc = null;
             DBManager DBase = new DBManager();
             Connection con = DBase.getConnection();
             String server_ip = null;
+            String username = null;
+            String password = null;
             try
             {
                 pStmt = con
                         .prepareStatement("SELECT * FROM servers WHERE server_id="
                                 + server_id);
                 rs = pStmt.executeQuery();
-                if (!rs.next())
-                {
+                if (!rs.next()) {
                     request.setAttribute("message",
                             "<font color='red'>DATABASE ERROR: Server id "
                                     + server_id
@@ -444,6 +444,9 @@
                     viewServer.include(request, response);
                     return;
                 }
+                server_ip = rs.getString("ip");
+                password = rs.getString("password");
+                username = rs.getString("username");
             }
             catch (SQLException e)
             {
@@ -453,14 +456,10 @@
                 viewServer.include(request, response);
                 return;
             }
-            try
-            {
-                server_ip = rs.getString("ip");
-                MRCConnection = new MRCConnector(server_ip, rs
-                        .getString("username"), rs.getString("password"));
-            }
-            catch (Exception e)
-            {
+            try {
+                con.close();
+                mrc = new MRCConnector(server_ip, username, password);
+            } catch (Exception e) {
                 request
                         .setAttribute("message",
                                 "<font color='red'>MRC ERROR: Unable to connect to server "
@@ -471,7 +470,7 @@
             }
             try
             {
-                if (MRCConnection.stopTrackingMbean(mbean))
+                if (mrc.stopTrackingMbean(mbean))
                 {
                     request.setAttribute("message", "<b>MBean " + mbean
                             + " removed from tracking on server "
@@ -510,19 +509,20 @@
         {
             PreparedStatement pStmt = null;
             ResultSet rs = null;
-            MRCConnector MRCConnection = null;
+            MRCConnector mrc = null;
             DBManager DBase = new DBManager();
             Connection con = DBase.getConnection();
             String server_id = request.getParameter("server_id");
             String server_ip = null;
+            String username = null;
+            String password = null;
             try
             {
                 pStmt = con
                         .prepareStatement("SELECT * FROM servers WHERE server_id="
                                 + server_id);
                 rs = pStmt.executeQuery();
-                if (!rs.next())
-                {
+                if (!rs.next()) {
                     request.setAttribute("message",
                             "<font color='red'>DATABASE ERROR: Server id "
                                     + server_id
@@ -530,23 +530,20 @@
                     normalView.include(request, response);
                     return;
                 }
-            }
-            catch (SQLException e)
-            {
+                server_ip = rs.getString("ip");
+                password = rs.getString("password");
+                username = rs.getString("username");
+            } catch (SQLException e) {
                 request.setAttribute("message",
                         "<font color='red'>DATABASE ERROR: " + e.getMessage()
                                 + "</font>");
                 normalView.include(request, response);
                 return;
             }
-            try
-            {
-                server_ip = rs.getString("ip");
-                MRCConnection = new MRCConnector(server_ip, rs
-                        .getString("username"), rs.getString("password"));
-            }
-            catch (Exception e)
-            {
+            try {
+                con.close();
+                mrc = new MRCConnector(server_ip, username, password);
+            } catch (Exception e) {
                 request
                         .setAttribute("message",
                                 "<font color='red'>MRC ERROR: Unable to connect to server "
@@ -557,7 +554,7 @@
             }
             try
             {
-                if (MRCConnection.stopSnapshotThread())
+                if (mrc.stopSnapshotThread())
                 {
                     request.setAttribute("message",
                             "<b>Snapshot thread stopped on server "
@@ -598,18 +595,18 @@
                     .getParameter("snapshotDuration"));
             PreparedStatement pStmt = null;
             ResultSet rs = null;
-            MRCConnector MRCConnection = null;
+            MRCConnector mrc = null;
             DBManager DBase = new DBManager();
             Connection con = DBase.getConnection();
             String server_ip = null;
-            try
-            {
+            String username = null;
+            String password = null;
+            try {
                 pStmt = con
                         .prepareStatement("SELECT * FROM servers WHERE server_id="
                                 + server_id);
                 rs = pStmt.executeQuery();
-                if (!rs.next())
-                {
+                if (!rs.next()) {
                     request.setAttribute("message",
                             "<font color='red'>DATABASE ERROR: Server id "
                                     + server_id
@@ -617,6 +614,9 @@
                     normalView.include(request, response);
                     return;
                 }
+                server_ip = rs.getString("ip");
+                password = rs.getString("password");
+                username = rs.getString("username");
             }
             catch (SQLException e)
             {
@@ -626,14 +626,10 @@
                 normalView.include(request, response);
                 return;
             }
-            try
-            {
-                server_ip = rs.getString("ip");
-                MRCConnection = new MRCConnector(server_ip, rs
-                        .getString("username"), rs.getString("password"));
-            }
-            catch (Exception e)
-            {
+            try {
+                con.close();
+                mrc = new MRCConnector(server_ip, username, password);
+            } catch (Exception e) {
                 request
                         .setAttribute("message",
                                 "<font color='red'>MRC ERROR: Unable to connect to server "
@@ -645,16 +641,12 @@
             try
             {
 
-                if (MRCConnection
-                        .startSnapshotThread(new Long(snapshotDuration)))
-                {
+                if (mrc.startSnapshotThread(new Long(snapshotDuration))) {
                     request.setAttribute("message",
                             "<b>Snapshot thread started on server "
                                     + rs.getString("name") + "</b>");
                     normalView.include(request, response);
-                }
-                else
-                {
+                } else {
                     request
                             .setAttribute(
                                     "message",
@@ -809,6 +801,7 @@
             request.setAttribute("password2", request.getParameter("password2"));
             request.setAttribute("message", request.getParameter("message"));
             request.setAttribute("server_id", request.getParameter("server_id"));
+            request.setAttribute("snapshot", request.getParameter("snapshot"));
             editServer.include(request, response);
         } else {
             editNormalView.include(request, response);
@@ -951,7 +944,7 @@
             }
             con.close();
             // update the server side db
-            MRCConnector.setSnapshotDuration(Long.parseLong(snapshot) * 1000 * 60);
+            (new MRCConnector(ip, username, password)).setSnapshotDuration(Long.parseLong(snapshot) * 1000 * 60);
             // set success message
             actionResponse.setRenderParameter(
                             "message",

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=599235&r1=599234&r2=599235&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 Nov 28 17:06:58 2007
@@ -44,6 +44,7 @@
 String username = (String) request.getAttribute("username");
 String password = (String) request.getAttribute("password");
 String password2 = (String) request.getAttribute("password2");
+String snapshot = (String) request.getAttribute("snapshot");
 if(message == null)
     message = "";
 if(name == null)
@@ -56,14 +57,19 @@
     password = "";
 if(password2 == null)
     password2 = "";
+if(snapshot == null)
+    snapshot = "";
 
 DBManager DBase = new DBManager();
 Connection con = DBase.getConnection();
 
 PreparedStatement pStmt = con.prepareStatement("SELECT * FROM servers WHERE server_id="+server_id);
 ResultSet rs = pStmt.executeQuery();
-MRCConnector MRCConnection = null;
+MRCConnector mrc = null;
 boolean isOnline = true;
+String added = "";
+String modified = "";
+String last_seen = "";
 
 if (rs.next()) {
     // name == "" when user has not submitted anything
@@ -72,14 +78,27 @@
         name = rs.getString("name");
         username = rs.getString("username");
         ip = rs.getString("ip");
+        password = rs.getString("password");
     }
+    added = rs.getString("added");
+    modified = rs.getString("modified");
+    last_seen = rs.getString("last_seen");
     try {
-        MRCConnection = new MRCConnector(rs.getString("ip"), rs.getString("username"), rs.getString("password"));
+        // 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;
       //TODO: Fix update here
         //rs2.updateTimestamp("last_seen", new Timestamp(System.currentTimeMillis()));
     } catch (Exception e) {
-        isOnline = false;
-        message = message + "<br><font color='red'><li>Server is offline</li></font>";
+        // 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>";
     }
 %>
 <!-- <head> -->
@@ -136,7 +155,7 @@
         <td width="90%" align="left" valign="top">
             <p>
             <font face="Verdana" size="+1">
-            Editing: <%=rs.getString("name")%> (<%=rs.getString("ip")%>)
+            Editing: <%=name%> (<%=ip%>)
             </font>
             </p>         
             <p>
@@ -145,19 +164,19 @@
     <tr>
       <td>Added:</td>
       <td>&nbsp;</td>
-      <td align="right"><%=rs.getString("added").substring(0,16)%></td>
+      <td align="right"><%=added.substring(0,16)%></td>
       <td></td>
     </tr>
     <tr>
       <td>Last Modified:</td>
       <td>&nbsp;</td>
-      <td align="right"><%=rs.getString("modified").substring(0,16)%></td>
+      <td align="right"><%=modified.substring(0,16)%></td>
       <td></td>
     </tr>
     <tr>
       <td>Last Seen:</td>
       <td>&nbsp;</td>
-      <td align="right"><%=rs.getString("last_seen").substring(0,16)%></td>
+      <td align="right"><%=last_seen.substring(0,16)%></td>
       <td></td>
     </tr>
     <tr>
@@ -179,7 +198,7 @@
     <tr>
       <td>Snapshot Duration:</td>
       <td>&nbsp;</td>
-      <td align="right"><input type="text" width="5" size="4" name="snapshot" onKeyUp='noAlpha(this)' onKeyPress='noAlpha(this)' value="<%=(Long)MRCConnection.getSnapshotDuration()/1000/60%>"/></td>
+      <td align="right"><input type="text" width="5" size="4" name="snapshot" onKeyUp='noAlpha(this)' onKeyPress='noAlpha(this)' value="<%=snapshot%>"/></td>
       <td> minutes</td>
     </tr>
     <%
@@ -246,8 +265,8 @@
                         &nbsp;<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 href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="disableServer" /><portlet:param name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Disable this server</a></li>
-                        <li><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="deleteServer" /><portlet:param name="server_id" value="<%=rs.getString("server_id")%>" /></portlet:actionURL>">Delete this server</a></li>
+                        <li><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="disableServer" /><portlet:param name="server_id" value="<%=server_id%>" /></portlet:actionURL>">Disable this server</a></li>
+                        <li><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="deleteServer" /><portlet:param name="server_id" value="<%=server_id%>" /></portlet:actionURL>">Delete this server</a></li>
                         <li><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="showAddServer" /></portlet:actionURL>">Add a new server</a></li>
                         </ul>
                         &nbsp;<br />
@@ -302,10 +321,6 @@
         </td>  
     </tr>
 </table>
-    <%
-    }%>
-
-
-
-
-
+<%
+}
+%>
\ No newline at end of file

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=599235&r1=599234&r2=599235&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 Wed Nov 28 17:06:58 2007
@@ -17,6 +17,7 @@
 --%>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
+<%@ page import="java.util.ArrayList" %>
 <%@ page import="java.sql.Connection" %>
 <%@ page import="java.sql.DatabaseMetaData" %>
 <%@ page import="java.sql.PreparedStatement" %>
@@ -71,7 +72,10 @@
   <td class="${backgroundClass}" width="15%" align="center"><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="showEditView" /><portlet:param name="view_id" value="<%=rs.getString("view_id")%>" /></portlet:actionURL>">Edit</a></td>
   <td class="${backgroundClass}" width="15%" align="center"><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="disableView" /><portlet:param name="view_id" value="<%=rs.getString("view_id")%>" /></portlet:actionURL>">Disable</a></td>
  </tr>
- <%} %>
+ <%
+ }
+ rs.close();
+ %>
 </table>
 <div align="right"><a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="showAddView" /></portlet:actionURL>">Create View</a></div>
 <table width="100%" style="border-style: solid;
@@ -88,41 +92,61 @@
  
  pStmt = con.prepareStatement("SELECT * FROM servers");
  rs = pStmt.executeQuery();
+ 
+ // data structure to store the server's info
+ class ServerInfo {
+     public String ip;
+     public String username;
+     public String password;
+     public String server_id;
+     public boolean enabled;
+     public String name;
+ }
+ 
+ ArrayList<ServerInfo> serverInfos = new ArrayList<ServerInfo>();
+ // for each server, save the information locally
+ while(rs.next()) {
+     ServerInfo s = new ServerInfo();
+     s.ip = rs.getString("ip");
+     s.username = rs.getString("username");
+     s.password = rs.getString("password");
+     s.server_id = rs.getString("server_id");
+     s.name = rs.getString("name");
+     s.enabled = rs.getInt("enabled") == 1 ? true : false;
+     serverInfos.add( s );
+ }
+ // close connection
  con.close();
- while (rs.next())
- {
+ // for each server, draw it
+ for(int i = 0 ; i < serverInfos.size(); i++) {
+     String ip = serverInfos.get(i).ip;
+     String username = serverInfos.get(i).username;
+     String password = serverInfos.get(i).password;
+     String server_id = serverInfos.get(i).server_id;
+     boolean enabled = serverInfos.get(i).enabled;
+     String name = serverInfos.get(i).name;
      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
-             .getString("username"), rs.getString("password"));
-         online = true;
-     }    
-     catch (Exception e)
-     {
-         online = false;
-     }
-     try
-     {
-         snapshotDuration = MRCConnection.getSnapshotDuration();
-         if (MRCConnection.isSnapshotRunning())
-             collecting = true;
-         else
-             collecting = false;
-     }
-     catch (Exception e)
-     {
-         collecting = false;
-         online = false;
-     }
+     if (enabled) {
+	     try {
+	         MRCConnection = new MRCConnector(ip, username, password);
+	         online = true;
+	     } catch (Exception e) {
+	         online = false;
+	     }
+	     try {
+	         snapshotDuration = MRCConnection.getSnapshotDuration();
+	         if (MRCConnection.isSnapshotRunning())
+	             collecting = true;
+	         else
+	             collecting = false;
+	     } catch (Exception e) {
+	         collecting = false;
+	         online = false;
+	     }
      }
-
  %>
   <c:set var="backgroundClass" value='MediumBackground'/>
   <c:choose>
@@ -137,14 +161,14 @@
  <%
 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>
+  <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="<%=server_id%>" /></portlet:actionURL>"><%=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="<%=server_id%>" /></portlet:actionURL>"><%=ip%></a></td>
 <%
 }
 else{
     %>
-    <td class="${backgroundClass}" width="30%" align="center"><%=rs.getString("name")%></td>
-    <td class="${backgroundClass}" width="10%" align="center"><%=rs.getString("ip")%></td>
+    <td class="${backgroundClass}" width="30%" align="center"><%=name%></td>
+    <td class="${backgroundClass}" width="10%" align="center"><%=ip%></td>
   <% 
 }
 if (online) {     // online
@@ -166,7 +190,7 @@
 <%
     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>
+        <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="<%=server_id%>" /><portlet:param name="snapshotDuration" value="<%=java.lang.Long.toString(snapshotDuration)%>" /></portlet:actionURL>">Enable Query</a></td>
 <%
     } else {        // do not provide links
 %>
@@ -174,15 +198,15 @@
 <%
     }
 %>
-  <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="showEditServer" /><portlet:param name="server_id" value="<%=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="view"><portlet:param name="action" value="stopThread" /><portlet:param name="server_id" value="<%=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="<%=server_id%>" /></portlet:actionURL>">Edit</a></td>
 <%
     }
     else
@@ -190,17 +214,17 @@
         %>
         <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>
+        <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="<%=server_id%>" /></portlet:actionURL>">Edit</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>
+  <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="<%=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>
+  <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="<%=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=599235&r1=599234&r2=599235&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 Wed Nov 28 17:06:58 2007
@@ -18,6 +18,7 @@
 <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
 <%@ page import="org.apache.geronimo.plugins.monitoring.client.StatsGraph" %>
 <%@ page import="org.apache.geronimo.plugins.monitoring.client.GraphsBuilder" %>
+<%@ page import="java.util.ArrayList" %>
 <%@ page import="java.util.Vector" %>
 <%@ page import="java.util.Set" %>
 <%@ page import="java.sql.Connection" %>
@@ -43,18 +44,35 @@
 
 if (rs.next())
 {
+    String name = rs.getString("name");
+    String description = rs.getString("description");
     pStmt = con.prepareStatement("SELECT * FROM views_graphs WHERE view_id="+view_id);
     ResultSet rs2 = pStmt.executeQuery();
+    ArrayList<Integer> ids = new ArrayList<Integer>();
+    while(rs2.next()) {
+        ids.add( new Integer(rs2.getInt("graph_id")) );
+    }
+    
+    rs.close();
+    rs2.close();
 
+    try {
+        if(con != null) {
+            con.close();
+        }
+    } catch(Exception e) {
+        
+    }
+    
     Vector <StatsGraph> graphs = new Vector<StatsGraph>();
-    while (rs2.next()) {
+    for(int i = 0 ; i < ids.size(); i++) {
         try {
-            StatsGraph graph = run.buildOneDB(rs2.getInt("graph_id"));
+            StatsGraph graph = run.buildOneDB( ids.get(i).intValue() );
             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>";
+            errors = errors + "<li>Graph " + ids.get(i) + " could not be drawn due to server being offline</li>";
         }
     }
     
@@ -107,10 +125,10 @@
             <a HREF="javascript:history.go(-1)"><< Back</a>
             <p>
             <font face="Verdana" size="+1">
-            <%=rs.getString("name")%>
+            <%=name%>
             </font>
             </p>         
-            <p><%=rs.getString("description")%></p>
+            <p><%=description%></p>
 
 <% 
 try
@@ -169,8 +187,6 @@
     </tr>
 </table>
 <%
-rs.close();
-rs2.close();
 }
     else
     {%>



Mime
View raw message