geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r820185 - in /geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main: java/org/apache/geronimo/monitoring/console/ java/org/apache/geronimo/monitoring/console/util/ resources/ webapp/WEB-INF/view/
Date Wed, 30 Sep 2009 06:43:36 GMT
Author: xuhaihong
Date: Wed Sep 30 06:43:35 2009
New Revision: 820185

URL: http://svn.apache.org/viewvc?rev=820185&view=rev
Log:
GERONIMO-4810 Predefine a "localhost" server with some predefined graphs and views (Patch from Vanessa)

Modified:
    geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/GraphsBuilder.java
    geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/MonitoringPortlet.java
    geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/util/DBManager.java
    geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_en.properties
    geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_ja.properties
    geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_en.properties
    geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_ja.properties
    geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp
    geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp

Modified: geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/GraphsBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/GraphsBuilder.java?rev=820185&r1=820184&r2=820185&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/GraphsBuilder.java (original)
+++ geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/GraphsBuilder.java Wed Sep 30 06:43:35 2009
@@ -14,10 +14,10 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
+
 package org.apache.geronimo.monitoring.console;
 
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.text.DecimalFormat;
@@ -29,13 +29,16 @@
 import java.util.Iterator;
 import java.util.TreeMap;
 
-import org.apache.geronimo.monitoring.console.util.DBManager;
-
 public class GraphsBuilder {
+
     private String ip = new String();
+
     private int timeFrame;
+
     private int snapCount;
+
     private MRCConnector mrc = null;
+
     private Connection con;
 
     // constructor
@@ -45,203 +48,160 @@
     }
 
     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);
-        ResultSet rs = pStmt.executeQuery();
-        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");
-            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");
-            boolean showArchive = rs.getInt("archive") == 1 ? true : false;
-
-            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");
-                int port = rsServer.getInt("port");
-                int protocol = rsServer.getInt("protocol");
-                // 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;
-                }
-                mrc = new MRCConnector(ip, username, password, port, protocol);
-                HashMap<String, ArrayList<Object>> DataList = new HashMap<String, ArrayList<Object>>();
-
-                DataList.put(graphName1, new ArrayList<Object>());
-                if ((dataName2 != null) && !dataName2.equals("time")
-                        && !dataName2.equals("null") && !dataName2.equals("")) {
-                    DataList.put(graphName2, new ArrayList<Object>());
-                }
-                if ((timeFrame / 1440 >= 30))
-                    snapCount = 17;
-                else {
-                    if ((timeFrame / 1440) == 7) {
-                        snapCount = 16;
-                    } else if ((int) ((timeFrame / (mrc.getSnapshotDuration() / 60000))) <= 12)
-                        snapCount = (int) ((timeFrame / (mrc
-                                .getSnapshotDuration() / 60000)));
-                    else
-                        snapCount = 12;
-                }
-
-                ArrayList<Object> snapshot_time = new ArrayList<Object>();
-
-                ArrayList<Object> PrettyTime = new ArrayList<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";
+        Statement graphStmt = null;
+        Statement serverStmt = null;
+        Statement updateStmt = null;
+        try {
+            graphStmt = con.createStatement();            
+            ResultSet rs = graphStmt.executeQuery("SELECT * from graphs WHERE enabled=1 AND graph_id=" + graph_id);
+            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");
+                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");
+                boolean showArchive = rs.getInt("archive") == 1 ? true : false;
+                serverStmt = con.createStatement();
+                ResultSet rsServer = serverStmt.executeQuery("SELECT * from servers WHERE enabled=1 AND server_id=" + server_id);
+                if (rsServer.next()) {
+                    ip = rsServer.getString("ip");
+                    String username = rsServer.getString("username");
+                    String password = rsServer.getString("password");
+                    int port = rsServer.getInt("port");
+                    int protocol = rsServer.getInt("protocol");
+                    rsServer.close();
+                    mrc = new MRCConnector(ip, username, password, port, protocol);
+                    HashMap<String, ArrayList<Object>> DataList = new HashMap<String, ArrayList<Object>>();
+                    DataList.put(graphName1, new ArrayList<Object>());
+                    if ((dataName2 != null) && !dataName2.equals("time") && !dataName2.equals("null") && !dataName2.equals("")) {
+                        DataList.put(graphName2, new ArrayList<Object>());
+                    }
+                    if ((timeFrame / 1440 >= 30))
+                        snapCount = 17;
+                    else {
+                        if ((timeFrame / 1440) == 7) {
+                            snapCount = 16;
+                        } else if ((int) ((timeFrame / (mrc.getSnapshotDuration() / 60000))) <= 12)
+                            snapCount = (int) ((timeFrame / (mrc.getSnapshotDuration() / 60000)));
+                        else
+                            snapCount = 12;
+                    }
+                    ArrayList<Object> snapshot_time = new ArrayList<Object>();
+                    ArrayList<Object> PrettyTime = new ArrayList<Object>();
+                    String prettyTimeFrame = new String();
+                    DecimalFormat fmt = new DecimalFormat("0.##");
+                    if (timeFrame / 60 > 24) {
+                        prettyTimeFrame = fmt.format((float) (timeFrame / 1440)) + " day";
                     } else {
-                        prettyTimeFrame = fmt.format(timeFrame) + " minute";
+                        if (timeFrame > 60) {
+                            prettyTimeFrame = fmt.format((float) timeFrame / 60) + " hour";
+                        } else {
+                            prettyTimeFrame = fmt.format(timeFrame) + " minute";
+                        }
                     }
-                }
-
-                int skipCount = (int) ((timeFrame / (mrc.getSnapshotDuration() / 60000)))
-                        / (snapCount);
-
-                snapCount = snapCount + 2;
-                TreeMap<Long, Long> snapshotList1 = mrc
-                        .getSpecificStatistics(mBeanName, dataName1, snapCount,
-                                skipCount, showArchive);
-                TreeMap<Long, Long> snapshotList2 = new TreeMap<Long, Long>();
-                if ((dataName2 != null) && !dataName2.equals("time")
-                        && !dataName2.equals("null") && !dataName2.equals("")) {
-                    snapshotList2 = mrc.getSpecificStatistics(mBeanName,
-                            dataName2, snapCount, skipCount, showArchive);
-                }
-                // Check if snapshotList is empty
-                if (snapshotList1.size() == 0) {
-                    snapshotList1.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 (snapshotList1.size() < snapCount) {
-                        // Temporary, always is first element (oldest)
-                        Long timeFix = snapshotList1.firstKey();
-                        // Calculate appropriate time, add it to the submap,
-                        // then
-                        // add
-                        // that to the tempMap
-                        snapshotList1
-                                .put(
-                                        (timeFix - (mrc.getSnapshotDuration() * skipCount)),
-                                        new Long(0));
+                    int skipCount = (int) ((timeFrame / (mrc.getSnapshotDuration() / 60000))) / (snapCount);
+                    snapCount = snapCount + 2;
+                    TreeMap<Long, Long> snapshotList1 = mrc.getSpecificStatistics(mBeanName, dataName1, snapCount, skipCount, showArchive);
+                    TreeMap<Long, Long> snapshotList2 = new TreeMap<Long, Long>();
+                    if ((dataName2 != null) && !dataName2.equals("time") && !dataName2.equals("null") && !dataName2.equals("")) {
+                        snapshotList2 = mrc.getSpecificStatistics(mBeanName, dataName2, snapCount, skipCount, showArchive);
                     }
-                }
-                if (snapshotList2.size() == 0) {
-                    snapshotList2.put(System.currentTimeMillis(), new Long(0));
-                    while (snapshotList2.size() < snapCount) {
-                        // Temporary, always is first element (oldest)
-                        Long timeFix = snapshotList2.firstKey();
-                        snapshotList2
-                                .put(
-                                        (timeFix - (mrc.getSnapshotDuration() * skipCount)),
-                                        new Long(0));
+                    // Check if snapshotList is empty
+                    if (snapshotList1.size() == 0) {
+                        snapshotList1.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 (snapshotList1.size() < snapCount) {
+                            // Temporary, always is first element (oldest)
+                            Long timeFix = snapshotList1.firstKey();
+                            // Calculate appropriate time, add it to the submap,
+                            // then
+                            // add
+                            // that to the tempMap
+                            snapshotList1.put((timeFix - (mrc.getSnapshotDuration() * skipCount)), new Long(0));
+                        }
                     }
-                }
-
-                for (Iterator<Long> it = snapshotList1.keySet().iterator(); it
-                        .hasNext();) {
-                    Long current = it.next();
-                    snapshot_time.add(current);
-                    ArrayList<Object> ArrayListTemp = DataList.get(graphName1);
-                    ArrayListTemp.add(snapshotList1.get(current));
-                    DataList.put(graphName1, ArrayListTemp);
-                    if ((dataName2 != null) && !dataName2.equals("time")
-                            && !dataName2.equals("null")
-                            && !dataName2.equals("")) {
-                        ArrayList<Object> ArrayListTemp2 = DataList
-                                .get(graphName2);
-                        ArrayListTemp2.add(snapshotList2.get(current));
-                        DataList.put(graphName2, ArrayListTemp2);
+                    if (snapshotList2.size() == 0) {
+                        snapshotList2.put(System.currentTimeMillis(), new Long(0));
+                        while (snapshotList2.size() < snapCount) {
+                            // Temporary, always is first element (oldest)
+                            Long timeFix = snapshotList2.firstKey();
+                            snapshotList2.put((timeFix - (mrc.getSnapshotDuration() * skipCount)), new Long(0));
+                        }
+                    }
+                    for (Iterator<Long> it = snapshotList1.keySet().iterator(); it.hasNext();) {
+                        Long current = it.next();
+                        snapshot_time.add(current);
+                        ArrayList<Object> ArrayListTemp = DataList.get(graphName1);
+                        ArrayListTemp.add(snapshotList1.get(current));
+                        DataList.put(graphName1, ArrayListTemp);
+                        if ((dataName2 != null) && !dataName2.equals("time") && !dataName2.equals("null") && !dataName2.equals("")) {
+                            ArrayList<Object> ArrayListTemp2 = DataList.get(graphName2);
+                            ArrayListTemp2.add(snapshotList2.get(current));
+                            DataList.put(graphName2, ArrayListTemp2);
+                        }
+                        PrettyTime.add((Long) current / 1000);
+                    }
+                    if (dataName2.equals("time")) {
+                        graph = (new StatsGraph(graph_id, ip + " - " + xlabel + " - " + prettyTimeFrame, description, xlabel, 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, xlabel, 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, xlabel, ylabel, data1operation.charAt(0), DataList.get(graphName1), operation, snapshot_time, (int) (mrc.getSnapshotDuration() / 1000), timeFrame, color, warninglevel1, warninglevel1);
+                    } else {
+                        graph = new StatsGraph();
                     }
-                    PrettyTime.add((Long) current / 1000);
-                }
-
-                if (dataName2.equals("time")) {
-                    graph = (new StatsGraph(graph_id, ip + " - " + xlabel
-                            + " - " + prettyTimeFrame, description, xlabel,
-                            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, xlabel,
-                            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, xlabel,
-                            ylabel, data1operation.charAt(0), DataList
-                                    .get(graphName1), operation, snapshot_time,
-                            (int) (mrc.getSnapshotDuration() / 1000),
-                            timeFrame, color, warninglevel1, warninglevel1));
-                } else {
-                    System.out.println("Using Null call.");
-                    graph = (new StatsGraph());
                 }
-            
             }
+            // 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 
+                updateStmt = con.createStatement();
+                updateStmt.executeUpdate("UPDATE GRAPHS SET LAST_SEEN='" + currentTime + "' WHERE GRAPH_ID=" + graph_id);                
+            }
+            return graph;
+        } finally {
+            if (updateStmt != null)
+                try {
+                    updateStmt.close();
+                } catch (Exception e) {
+                }
+            if (serverStmt != null)
+                try {
+                    serverStmt.close();
+                } catch (Exception e) {
+                }
+            if (graphStmt != null)
+                try {
+                    graphStmt.close();
+                } catch (Exception e) {
+                }
+            if (mrc != null)
+                try {
+                    mrc.dispose();
+                } catch (Exception e) {
+                }
         }
-        mrc.dispose();
-        // 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/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/MonitoringPortlet.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/MonitoringPortlet.java?rev=820185&r1=820184&r2=820185&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/MonitoringPortlet.java (original)
+++ geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/MonitoringPortlet.java Wed Sep 30 06:43:35 2009
@@ -23,6 +23,8 @@
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
@@ -33,14 +35,20 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.console.BasePortlet;
-import org.apache.geronimo.monitoring.console.util.DBManager;
+import org.apache.geronimo.console.util.PortletManager;
 import org.apache.geronimo.crypto.EncryptionManager;
+import org.apache.geronimo.management.geronimo.WebContainer;
+import org.apache.geronimo.monitoring.console.util.DBManager;
 
 /**
  * STATS
  */
 public class MonitoringPortlet extends BasePortlet {
+    
+    private static final Log log = LogFactory.getLog(MonitoringPortlet.class);
 
     private static final String NORMALVIEW_JSP = "/WEB-INF/view/monitoringNormal.jsp";
 
@@ -97,6 +105,8 @@
     private PortletRequestDispatcher helpView;
 
     private PortletRequestDispatcher editNormalView;
+    
+    private String serverType;
 
     @Override
     public void processAction(ActionRequest actionRequest,
@@ -240,6 +250,9 @@
             actionResponse.setRenderParameter("port", "" + port);
             actionResponse.setRenderParameter("protocol", "" + protocol);
         }
+        else if(action.equals("restoreData")){
+            restoreData(actionRequest);
+        }
     }
 
     private void testConnection(String ip, String username,
@@ -369,6 +382,7 @@
     protected void doEdit(RenderRequest request, RenderResponse response)
             throws PortletException, IOException {
         String action = request.getParameter("action");
+        if(request.isUserInRole("admin")){
         if (action == null)
             action = "showNormal";
         if (action.equals("showEditView")) {
@@ -460,6 +474,7 @@
         } else {
             normalView.include(request, response);
         }
+        }//end admin
     }
 
     private void updateView(ActionRequest actionRequest,
@@ -1132,6 +1147,269 @@
         }
     }
 
+    private void restoreData(PortletRequest request) {
+        Connection conn = null;
+        try {
+            conn = DBManager.createConnection();
+            deleteDefaultServerView(conn);
+            initializeDefaultServerView(conn);
+            addInfoMessage(request, getLocalizedString(request, "infoMsg17"));
+        } catch (Exception e) {
+            addErrorMessage(request, getLocalizedString(request, "errorMsg20"), e.getMessage());
+        } finally {
+            if (conn != null)
+                try {
+                    conn.close();
+                } catch (Exception e) {
+                }
+        }
+    }
+    
+    private String getObjectNameByShortName(String shortName) {
+        try {
+            Object targetGBean = PortletManager.getKernel().getGBean(shortName);
+            return PortletManager.getKernel().getAbstractNameFor(targetGBean).getObjectName().getCanonicalName();
+        } catch (Exception e) {
+            log.error("Fail to find the gbean object for the short name " + shortName);
+            return null;
+        }
+    }
+
+    private void initializeDefaultServerView(Connection conn) throws PortletException {
+        PreparedStatement preparedStmt = null;
+        try {
+            preparedStmt = conn.prepareStatement("select server_id from servers where ip='localhost' and protocol=1");
+            ResultSet rs = preparedStmt.executeQuery();
+            if (rs.next()) {
+                return;
+            }
+            if (serverType.equals(WEB_SERVER_TOMCAT)) {
+                initializeDefaultTomatServerView(conn);
+            } else if (serverType.equals(WEB_SERVER_JETTY)) {
+                initializeDefaultJettyServerView(conn);
+            }
+        } catch (SQLException e) {
+            throw new PortletException(e);
+        } finally {
+            if (preparedStmt != null)
+                try {
+                    preparedStmt.close();
+                } catch (Exception e) {
+                }
+        }
+    }
+    
+    private void initializeDefaultTomatServerView(Connection conn) throws SQLException {
+        int serverId = insertServer(conn, "Default Server", "localhost", "", "", "1099", "1");
+        PreparedStatement preparedStmt = null;
+        try {
+            preparedStmt = conn.prepareStatement(
+                    "INSERT INTO graphs (server_id, name, description, timeframe, mbean, dataname1, xlabel, ylabel, data1operation, operation, data2operation, dataname2, warninglevel1, warninglevel2, added, modified, last_seen, archive,enabled) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,0,0,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,0,0)",
+                    Statement.RETURN_GENERATED_KEYS);
+            int jvmGraphId = insertGraph(preparedStmt, "JVM Heap Size Current", serverId, "JVM Heap Size Current", 60, getObjectNameByShortName("JVM"), "JVM Heap Size Current", "JVM Heap Size Current", "Time", "A", "", "A", "");
+            String tomcatWebConnectorObjectName = getObjectNameByShortName("TomcatWebConnector");
+            if (tomcatWebConnectorObjectName != null) {
+                List<Integer> graphIdList = new ArrayList<Integer>(15);
+                graphIdList.add(jvmGraphId);
+                graphIdList.add(insertGraph(preparedStmt, "Active Request Count", serverId, "Active Request Count", 60, tomcatWebConnectorObjectName, "Active Request Count", "Active Request Count", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Busy Threads Max", serverId, "Busy Threads Max", 60, tomcatWebConnectorObjectName, "Busy Threads Max", "Busy Threads Max", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Busy Threads Current", serverId, "Busy Threads Current", 60, tomcatWebConnectorObjectName, "Busy Threads Current", "Busy Threads Current", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Busy Threads Min", serverId, "Busy Threads Min", 60, tomcatWebConnectorObjectName, "Busy Threads Min", "Busy Threads Min", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Bytes Received", serverId, "Bytes Received", 60, tomcatWebConnectorObjectName, "Bytes Received", "Bytes Received", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Bytes Sent", serverId, "Bytes Sent", 60, tomcatWebConnectorObjectName, "Bytes Sent", "Bytes Sent", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Error Count", serverId, "Error Count", 60, tomcatWebConnectorObjectName, "Error Count", "Error Count", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Open Connections Current", serverId, "Open Connections Current", 60, tomcatWebConnectorObjectName, "Open Connections Current", "Open Connections Current", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Open Connections Max", serverId, "Open Connections Max", 60, tomcatWebConnectorObjectName, "Open Connections Max", "Open Connections Max", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Open Connections Min", serverId, "Open Connections Min", 60, tomcatWebConnectorObjectName, "Open Connections Min", "Open Connections Min", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Request Time CurrentTime", serverId, "Request Time CurrentTime", 60, tomcatWebConnectorObjectName, "Request Time CurrentTime", "Request Time CurrentTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Request Time MaxTime", serverId, "Request Time MaxTime", 60, tomcatWebConnectorObjectName, "Request Time MaxTime", "Request Time MaxTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Request Time MinTime", serverId, "Request Time MinTime", 60, tomcatWebConnectorObjectName, "Request Time MinTime", "Request Time MinTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Request Time TotalTime", serverId, "Request Time TotalTime", 60, tomcatWebConnectorObjectName, "Request Time TotalTime", "Request Time TotalTime", "Time", "A", "", "A", ""));
+                insertView(conn, graphIdList.toArray(new Integer[0]), "TomcatWebConnector View", "TomcatWebConnector View");
+            }
+            String tomcatWebSSLConnectorObjectName = getObjectNameByShortName("TomcatWebSSLConnector");
+            if (tomcatWebSSLConnectorObjectName != null) {
+                List<Integer> graphIdList = new ArrayList<Integer>(15);
+                graphIdList.add(jvmGraphId);
+                graphIdList.add(insertGraph(preparedStmt, "SSL Active Request Count", serverId, "Active Request Count", 60, tomcatWebSSLConnectorObjectName, "Active Request Count", "Active Request Count", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Busy Threads Current", serverId, "Busy Threads Current", 60, tomcatWebSSLConnectorObjectName, "Busy Threads Current", "Busy Threads Current", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Busy Threads Max", serverId, "Busy Threads Max", 60, tomcatWebSSLConnectorObjectName, "Busy Threads Max", "Busy Threads Max", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Busy Threads Min", serverId, "Busy Threads Min", 60, tomcatWebSSLConnectorObjectName, "Busy Threads Min", "Busy Threads Min", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Bytes Received", serverId, "Bytes Received", 60, tomcatWebSSLConnectorObjectName, "Bytes Received", "Bytes Received", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Bytes Sent", serverId, "Bytes Sent", 60, tomcatWebSSLConnectorObjectName, "Bytes Sent", "Bytes Sent", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Error Count", serverId, "Error Count", 60, tomcatWebSSLConnectorObjectName, "Error Count", "Error Count", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Open Connections Current", serverId, "Open Connections Current", 60, tomcatWebSSLConnectorObjectName, "Open Connections Current", "Open Connections Current", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Open Connections Max", serverId, "Open Connections Max", 60, tomcatWebSSLConnectorObjectName, "Open Connections Max", "Open Connections Max", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Open Connections Min", serverId, "Open Connections Min", 60, tomcatWebSSLConnectorObjectName, "Open Connections Min", "Open Connections Min", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Request Time CurrentTime", serverId, "Request Time CurrentTime", 60, tomcatWebSSLConnectorObjectName, "Request Time CurrentTime", "Request Time CurrentTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Request Time MaxTime", serverId, "Request Time MaxTime", 60, tomcatWebSSLConnectorObjectName, "Request Time MaxTime", "Request Time MaxTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Request Time MinTime", serverId, "Request Time MinTime", 60, tomcatWebSSLConnectorObjectName, "Request Time MinTime", "Request Time MinTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Request Time TotalTime", serverId, "Request Time TotalTime", 60, tomcatWebSSLConnectorObjectName, "Request Time TotalTime", "Request Time TotalTime", "Time", "A", "", "A", ""));
+                insertView(conn, graphIdList.toArray(new Integer[0]), "TomcatWebSSLConnector View", "TomcatWebSSLConnector View");
+            }
+        } finally {
+            if (preparedStmt != null)
+                try {
+                    preparedStmt.close();
+                } catch (Exception e) {
+                }
+        }
+    }
+
+    private void initializeDefaultJettyServerView(Connection conn) throws SQLException {
+        int serverId = insertServer(conn, "Default Server", "localhost", "", "", "1099", "1");
+        PreparedStatement preparedStmt = null;
+        try {
+            preparedStmt = conn.prepareStatement(
+                    "INSERT INTO graphs (server_id, name, description, timeframe, mbean, dataname1, xlabel, ylabel, data1operation, operation, data2operation, dataname2, warninglevel1, warninglevel2, added, modified, last_seen, archive,enabled) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,0,0,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,0,0)",
+                    Statement.RETURN_GENERATED_KEYS);
+            int jvmGraphId = insertGraph(preparedStmt, "JVM Heap Size Current", serverId, "JVM Heap Size Current", 60, getObjectNameByShortName("JVM"), "JVM Heap Size Current", "JVM Heap Size Current", "Time", "A", "", "A", "");
+            String jettyWebConnectorObjectName = getObjectNameByShortName("JettyWebConnector");
+            if (jettyWebConnectorObjectName != null) {
+                List<Integer> graphIdList = new ArrayList<Integer>();
+                graphIdList.add(jvmGraphId);
+                graphIdList.add(insertGraph(preparedStmt, "Connections Duration Count", serverId, "Connections Duration Count", 60, jettyWebConnectorObjectName, "Connections Duration Count", "Connections Duration Count", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Connections Duration MaxTime", serverId, "Connections Duration MaxTime", 60, jettyWebConnectorObjectName, "Connections Duration MaxTime", "Connections Duration MaxTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Connections Duration MinTime", serverId, "Connections Duration MinTime", 60, jettyWebConnectorObjectName, "Connections Duration MinTime", "Connections Duration MinTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Connections Duration TotalTime", serverId, "Connections Duration TotalTime", 60, jettyWebConnectorObjectName, "Connections Duration TotalTime", "Connections Duration TotalTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Connections Request Current", serverId, "Connections Request Current", 60, jettyWebConnectorObjectName, "Connections Request Current", "Connections Request Current", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Connections Request Max", serverId, "Connections Request Max", 60, jettyWebConnectorObjectName, "Connections Request Max", "Connections Request Max", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Connections Request Min", serverId, "Connections Request Min", 60, jettyWebConnectorObjectName, "Connections Request Min", "Connections Request Min", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Open Connections Current", serverId, "Open Connections Current", 60, jettyWebConnectorObjectName, "Open Connections Current", "Open Connections Current", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Open Connections Max", serverId, "Open Connections Max", 60, jettyWebConnectorObjectName, "Open Connections Max", "Open Connections Max", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Open Connections Min", serverId, "Open Connections Min", 60, jettyWebConnectorObjectName, "Open Connections Min", "Open Connections Min", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "Request Time CurrentTime", serverId, "Request Time CurrentTime", 60, jettyWebConnectorObjectName, "Request Time CurrentTime", "Request Time CurrentTime", "Time", "A", "", "A", ""));
+                insertView(conn, graphIdList.toArray(new Integer[0]), "JettyWebConnector View", "JettyWebConnector View");
+            }
+            String jettyWebSSLConnectorObjectName = getObjectNameByShortName("JettySSLConnector");
+            if (jettyWebSSLConnectorObjectName != null) {
+                List<Integer> graphIdList = new ArrayList<Integer>();
+                graphIdList.add(jvmGraphId);
+                graphIdList.add(insertGraph(preparedStmt, "SSL Connections Duration Count", serverId, "Connections Duration Count", 60, jettyWebSSLConnectorObjectName, "Connections Duration Count", "Connections Duration Count", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Connections Duration MaxTime", serverId, "Connections Duration MaxTime", 60, jettyWebSSLConnectorObjectName, "Connections Duration MaxTime", "Connections Duration MaxTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Connections Duration MinTime", serverId, "Connections Duration MinTime", 60, jettyWebSSLConnectorObjectName, "Connections Duration MinTime", "Connections Duration MinTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Connections Duration TotalTime", serverId, "Connections Duration TotalTime", 60, jettyWebSSLConnectorObjectName, "Connections Duration TotalTime", "Connections Duration TotalTime", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Connections Request Current", serverId, "Connections Request Current", 60, jettyWebSSLConnectorObjectName, "Connections Request Current", "Connections Request Current", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Connections Request Max", serverId, "Connections Request Max", 60, jettyWebSSLConnectorObjectName, "Connections Request Max", "Connections Request Max", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Connections Request Min", serverId, "Connections Request Min", 60, jettyWebSSLConnectorObjectName, "Connections Request Min", "Connections Request Min", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Open Connections Current", serverId, "Open Connections Current", 60, jettyWebSSLConnectorObjectName, "Open Connections Current", "Open Connections Current", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Open Connections Max", serverId, "Open Connections Max", 60, jettyWebSSLConnectorObjectName, "Open Connections Max", "Open Connections Max", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Open Connections Min", serverId, "Open Connections Min", 60, jettyWebSSLConnectorObjectName, "Open Connections Min", "Open Connections Min", "Time", "A", "", "A", ""));
+                graphIdList.add(insertGraph(preparedStmt, "SSL Request Time CurrentTime", serverId, "Request Time CurrentTime", 60, jettyWebSSLConnectorObjectName, "Request Time CurrentTime", "Request Time CurrentTime", "Time", "A", "", "A", ""));
+                insertView(conn, graphIdList.toArray(new Integer[0]), "JettyWebSSLConnector View", "JettyWebSSLConnector View");
+            }
+        } finally {
+            if (preparedStmt != null)
+                try {
+                    preparedStmt.close();
+                } catch (Exception e) {
+                }
+        }                      
+    }
+
+    private int insertServer(Connection conn, String name, String ip, String username, String password, String port, String protocol) throws SQLException {
+        Statement stmt = null;
+        try {
+            stmt = conn.createStatement();
+            stmt.execute("INSERT INTO servers (enabled ,name, ip, username, password, modified, last_seen, added, port, protocol) VALUES (" + "0" + ",'" + name + "','" + ip + "','" + username + "','" + password + "',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP," + port + "," + protocol + ")", Statement.RETURN_GENERATED_KEYS);
+            ResultSet rs = stmt.getGeneratedKeys();
+            if (rs.next()) {
+                return rs.getInt(1);
+            } else {
+                throw new SQLException("Fail to insert the new server " + name);
+            }
+        } finally {
+            if (stmt != null)
+                try {
+                    stmt.close();
+                } catch (Exception e) {
+                }
+        }
+    }
+
+    private int insertGraph(PreparedStatement stmt, String name, int server_id, String description, int timeframe, String mbean, String dataname1, String xlabel, String ylabel, String data1operation, String operation, String data2operation, String dataname2) throws SQLException {
+        stmt.setInt(1, server_id);
+        stmt.setString(2, name);
+        stmt.setString(3, description);
+        stmt.setInt(4, timeframe);
+        stmt.setString(5, mbean);
+        stmt.setString(6, dataname1);
+        stmt.setString(7, xlabel);
+        stmt.setString(8, ylabel);
+        stmt.setString(9, data1operation);
+        stmt.setString(10, operation);
+        stmt.setString(11, data2operation);
+        stmt.setString(12, dataname2);
+        if (stmt.executeUpdate() == 1) {
+            ResultSet rs = stmt.getGeneratedKeys();
+            if (rs.next()) {
+                return rs.getInt(1);
+            }
+        }
+        throw new SQLException("Fail to insert the graph " + name);
+    }
+
+    private void insertView(Connection conn, Integer[] graphIds, String name, String description) throws SQLException {
+        Statement viewStmt = null;
+        PreparedStatement preparedStmt = null;
+        try {
+            viewStmt = conn.createStatement();
+            viewStmt.executeUpdate("INSERT INTO views (name, description, graph_count, modified, added) VALUES ('" + name + "','" + description + "'," + graphIds.length + ",CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)", Statement.RETURN_GENERATED_KEYS);
+            ResultSet rs = viewStmt.getGeneratedKeys();
+            if (rs.next()) {
+                int viewId = rs.getInt(1);
+                preparedStmt = conn.prepareStatement("INSERT INTO views_graphs VALUES(?,?)");
+                for (int i = 0; i < graphIds.length; i++) {
+                    preparedStmt.setInt(1, viewId);
+                    preparedStmt.setInt(2, graphIds[i]);
+                    preparedStmt.executeUpdate();
+                }
+            }
+        } finally {
+            if (viewStmt != null)
+                try {
+                    viewStmt.close();
+                } catch (Exception e) {
+                }
+            if (preparedStmt != null)
+                try {
+                    preparedStmt.close();
+                } catch (Exception e) {
+                }
+        }
+    }
+
+    public void deleteDefaultServerView(Connection con) throws SQLException {       
+        Statement stmt = null;
+        try {
+            stmt = con.createStatement();
+            ResultSet rs = stmt.executeQuery("select server_id from servers where ip='localhost' and protocol=1");
+            int server_id;
+            if (rs.next()) {
+                server_id = rs.getInt("server_id");
+            } else {
+                return;
+            }
+            rs.close();
+            /**
+             * 1. Delete all the relation records in the view_graphs
+             * 2. Delete all empty view from views
+             * 3. Delete all the graphs of the target server
+             * 4. Delete the target server record
+             */
+            stmt.execute("delete from views_graphs where exists (select * from graphs where views_graphs.graph_id = graphs.graph_id and graphs.server_id=" + server_id + ")");
+            stmt.execute("delete from views where not exists (select * from views_graphs where views_graphs.view_id=views.view_id)");
+            stmt.execute("delete from graphs where server_id=" + server_id);
+            stmt.execute("delete from servers where server_id=" + server_id);
+        } finally {
+            if (stmt != null)
+                try {
+                    stmt.close();
+                } catch (Exception e) {
+                }
+        }
+    }
+
     @Override
     public void init(PortletConfig portletConfig) throws PortletException {
         super.init(portletConfig);
@@ -1163,6 +1441,22 @@
                 HELPVIEW_JSP);
         editNormalView = portletConfig.getPortletContext()
                 .getRequestDispatcher(EDITNORMALVIEW_JSP);
+        
+        Connection conn = null;
+        try {
+            serverType = getWebServerType(PortletManager.getKernel().getGBean(WebContainer.class).getClass());
+            conn = new DBManager().getConnection();
+            initializeDefaultServerView(conn);
+        } catch (Exception e) {
+            log.error("Initialization failed",e);
+        } finally {
+            if (conn != null)
+                try {
+                    conn.close();
+                } catch (Exception e) {
+                }
+        }
+        
     }
 
     @Override

Modified: geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/util/DBManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/util/DBManager.java?rev=820185&r1=820184&r2=820185&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/util/DBManager.java (original)
+++ geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/java/org/apache/geronimo/monitoring/console/util/DBManager.java Wed Sep 30 06:43:35 2009
@@ -27,10 +27,14 @@
 import javax.naming.NamingException;
 import javax.sql.DataSource;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 public class DBManager
 {
-    private static Connection con         = null;
+    private Connection con         = null;
     private static boolean    initialized = false;
+    private static final Log log = LogFactory.getLog(DBManager.class);
 
     public DBManager()
     {
@@ -40,27 +44,16 @@
                 initialized = true;
     }
 
-    public static Connection createConnection()
-    {
-
-        try
-        {
+    public static Connection createConnection() {
+        try {
             Context context = new InitialContext();
-            DataSource ds = (DataSource) context
-                    .lookup("java:comp/env/MonitoringClientDS");
-            con = ds.getConnection();
+            DataSource ds = (DataSource) context.lookup("java:comp/env/MonitoringClientDS");
+            return ds.getConnection();
+        } catch (NamingException e) {
+            return null;
+        } catch (SQLException e) {
+            return null;
         }
-        catch (NamingException e)
-        {
-            e.printStackTrace();
-        }
-        catch (SQLException e)
-        {
-            System.err.println("SQL state: " + e.getSQLState());
-            System.err.println("SQL error: " + e.getErrorCode());
-            e.printStackTrace();
-        }
-        return con;
     }
 
     public Connection getConnection()
@@ -73,29 +66,26 @@
         return initialized;
     }
 
-    private boolean checkTables()
-    {
-        try
-        {
+    private boolean checkTables() {
+        ResultSet tableNames = null;
+        try {
             DatabaseMetaData metadata = null;
             metadata = con.getMetaData();
             String[] names = { "TABLE" };
-            ResultSet tableNames = metadata.getTables(null, null, null, names);
-
-            if (tableNames.next())
-            {
+            tableNames = metadata.getTables(null, null, null, names);
+            if (tableNames.next()) {
                 return true;
-            }
-            else
-            {
+            } else {
                 return false;
             }
-        }
-        catch (SQLException e)
-        {
-            System.err.println("SQL state: " + e.getSQLState());
-            System.err.println("SQL error: " + e.getErrorCode());
-            e.printStackTrace();
+        } catch (SQLException e) {
+            log.error("Fail to check tables", e);
+        } finally {
+            if (tableNames != null)
+                try {
+                    tableNames.close();
+                } catch (Exception e) {
+                }
         }
         return false;
     }
@@ -105,9 +95,10 @@
         boolean success = false;
         if (checkTables())
             return true;
+        PreparedStatement pStmt = null;
         try
         {
-            PreparedStatement pStmt = con
+            pStmt = con
                     .prepareStatement("CREATE TABLE servers("
                             + "server_id   INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1),"
                             + "enabled     SMALLINT DEFAULT 1 NOT NULL,"
@@ -123,6 +114,7 @@
                             + "CONSTRAINT  UNQ_IP_PORT UNIQUE(ip,port)"
                             + ")");
             pStmt.executeUpdate();
+            pStmt.close();
             pStmt = con
                     .prepareStatement("CREATE TABLE graphs("
                             + "graph_id    INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1),"
@@ -148,6 +140,7 @@
                             + "archive     SMALLINT NOT NULL DEFAULT 0,"
                             + "last_seen   TIMESTAMP NOT NULL" + ")");
             pStmt.executeUpdate();
+            pStmt.close();
             pStmt = con
                     .prepareStatement("CREATE TABLE views("
                             + "view_id     INTEGER PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1),"
@@ -158,17 +151,23 @@
                             + "added       TIMESTAMP NOT NULL,"
                             + "modified    TIMESTAMP NOT NULL)");
             pStmt.executeUpdate();
+            pStmt.close();
             pStmt = con.prepareStatement("CREATE TABLE views_graphs("
                     + "view_id     INTEGER NOT NULL,"
                     + "graph_id     INTEGER NOT NULL)");
             pStmt.executeUpdate();
+            pStmt.close();
             success = true;
         }
-        catch (SQLException e)
-        {
-            System.err.println("SQL state: " + e.getSQLState());
-            System.err.println("SQL error: " + e.getErrorCode());
-            e.printStackTrace();
+        catch (SQLException e) {
+            log.error("Fail to initialize DB", e);
+        } finally
+        {
+            if (pStmt != null)
+                try {
+                    pStmt.close();
+                } catch (Exception e) {
+                }
         }
         return success;
     }

Modified: geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_en.properties
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_en.properties?rev=820185&r1=820184&r2=820185&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_en.properties (original)
+++ geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_en.properties Wed Sep 30 06:43:35 2009
@@ -41,6 +41,7 @@
 monitor.common.st                 = something
 monitor.common.unknown            = Unknown
 monitor.common.view               = Views
+monitor.common.restore            = Reset
 monitor.edit.desc                 = This is the edit page for the Monitoring Portlet
 monitor.edit.msg01                = Click on 'Monitoring &rarr; Add Server'. Choose
 monitor.edit.msg02                = The Server 'localhost' will appear 'online' i.e. the monitoring console can talk to it.

Modified: geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_ja.properties
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_ja.properties?rev=820185&r1=820184&r2=820185&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_ja.properties (original)
+++ geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/monitor-portlet_ja.properties Wed Sep 30 06:43:35 2009
@@ -41,6 +41,7 @@
 monitor.common.st                 = \u4F55\u304B\u8A18\u8FF0
 monitor.common.unknown            = \u672A\u77E5
 monitor.common.view               = \u30D3\u30E5\u30FC
+monitor.common.restore            = Reset
 monitor.edit.desc                 = \u3053\u308C\u306F\u30E2\u30CB\u30BF\u30EA\u30F3\u30B0\u30FB\u30DD\u30FC\u30C8\u30EC\u30C3\u30C8\u306E\u7DE8\u96C6\u753B\u9762\u3067\u3059
 monitor.edit.msg01                = \u30E2\u30CB\u30BF\u30EA\u30F3\u30B0\u3092\u30AF\u30EA\u30C3\u30AF &rarr; \u65B0\u898F\u30B5\u30FC\u30D0\u30FC\u306E\u8FFD\u52A0\u3092\u9078\u629E
 monitor.edit.msg02                = \u30B5\u30FC\u30D0\u30FC 'localhost' \u306F\u30AA\u30F3\u30E9\u30A4\u30F3\u3067\u3057\u3087\u3046\u3002\u3059\u306A\u308F\u3061\u30E2\u30CB\u30BF\u30EA\u30F3\u30B0\u30FB\u30B3\u30F3\u30BD\u30FC\u30EB\u306F\u901A\u4FE1\u3059\u308B\u4E8B\u304C\u3067\u304D\u307E\u3059\u3002\r\n

Modified: geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_en.properties
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_en.properties?rev=820185&r1=820184&r2=820185&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_en.properties (original)
+++ geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_en.properties Wed Sep 30 06:43:35 2009
@@ -55,6 +55,8 @@
 
 errorMsg19 = Error encountered while deleting graph.
 
+errorMsg20 = Error encountered while reseting data.
+
 infoMsg01 = Connection was successfully established.
 
 infoMsg02 = Server <b>{0}</b> was successfully enabled.
@@ -85,4 +87,6 @@
 
 infoMsg15 = Graph <b>{0}</b> has been updated.
 
-infoMsg16 = Graph <b>{0}</b> has been deleted.
\ No newline at end of file
+infoMsg16 = Graph <b>{0}</b> has been deleted.
+
+infoMsg17 = Default Data reset.
\ No newline at end of file

Modified: geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_ja.properties
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_ja.properties?rev=820185&r1=820184&r2=820185&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_ja.properties (original)
+++ geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/resources/portletinfo_ja.properties Wed Sep 30 06:43:35 2009
@@ -55,6 +55,8 @@
 
 errorMsg19 = \u30b0\u30e9\u30d5\u306e\u524a\u9664\u4e2d\u306b\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002
 
+errorMsg20 = Error encountered while reseting data.
+
 infoMsg01 = \u63a5\u7d9a\u306f\u6210\u529f\u3057\u307e\u3057\u305f\u3002
 
 infoMsg02 = \u30b5\u30fc\u30d0\u30fc <b>{0}</b> \u3092\u6709\u52b9\u5316\u3057\u307e\u3057\u305f\u3002
@@ -86,3 +88,5 @@
 infoMsg15 = \u30b0\u30e9\u30d5 <b>{0}</b> \u3092\u66f4\u65b0\u3057\u307e\u3057\u305f\u3002
 
 infoMsg16 = \u30b0\u30e9\u30d5 <b>{0}</b> \u3092\u524a\u9664\u3057\u307e\u3057\u305f\u3002
+
+infoMsg17 = Default Data reset.

Modified: geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp?rev=820185&r1=820184&r2=820185&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp (original)
+++ geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringNormal.jsp Wed Sep 30 06:43:35 2009
@@ -38,7 +38,20 @@
 //-->
 </script>
 
+<script type = "text/javascript">
+<!--
+function confirm_del() {
+    var msg = "All the changes you made to default servers/views/graphs will be lost.\nAre you sure you want to proceed?";
+    return confirm(msg);
+}
+//-->
+</script>
 <CommonMsg:commonMsg/>
+<%if (request.isUserInRole("admin")){ %>
+<div align="left">
+<a><strong>Note:&nbsp</strong>To reset default servers/views/graphs, please click this link:</a>&nbsp&nbsp
+<a href="<portlet:actionURL portletMode="edit"><portlet:param name="action" value="restoreData" /></portlet:actionURL>" onclick="return confirm_del()"><fmt:message key="monitor.common.restore"/></a></div>
+<%} %>
 
 <br>
 <table width="100%" style="border-style: solid;

Modified: geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp?rev=820185&r1=820184&r2=820185&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp (original)
+++ geronimo/server/branches/2.1/plugins/monitoring/mconsole-war/src/main/webapp/WEB-INF/view/monitoringPage.jsp Wed Sep 30 06:43:35 2009
@@ -20,7 +20,7 @@
 <%@ taglib uri="/WEB-INF/CommonMsg.tld" prefix="CommonMsg"%>
 <%@ page import="org.apache.geronimo.monitoring.console.StatsGraph" %>
 <%@ page import="org.apache.geronimo.monitoring.console.GraphsBuilder" %>
-<%@ page import="java.util.ArrayList" %>
+<%@ page import="java.util.ArrayList,java.util.List" %>
 <%@ page import="java.util.Set" %>
 <%@ page import="java.sql.Connection" %>
 <%@ page import="java.sql.DatabaseMetaData" %>
@@ -33,49 +33,53 @@
 
 <%
 
-String view_id = (String) request.getAttribute("view_id"); 
-
-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 AND view_id="+view_id);
-ResultSet rs = pStmt.executeQuery();
-GraphsBuilder run = new GraphsBuilder(con);
-
-if (rs.next())
+String view_id = (String) request.getAttribute("view_id");
+Connection con = null;
+List <StatsGraph> graphs = new ArrayList<StatsGraph>();
+String name = null;
+String description = null;
+try
 {
-    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")) );
-    }
+	con = DBManager.createConnection();	
+	PreparedStatement pStmt = con.prepareStatement("SELECT view_id, name, description, graph_count, added, modified FROM views WHERE enabled=1 AND view_id="+view_id);
+	ResultSet rs = pStmt.executeQuery();
+	GraphsBuilder run = new GraphsBuilder(con);
+
+	if (rs.next())
+	{
+    	name = rs.getString("name");
+    	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) {
-        
-    }
+    	rs.close();
+    	rs2.close();    	
     
-    ArrayList <StatsGraph> graphs = new ArrayList<StatsGraph>();
-    for(int i = 0 ; i < ids.size(); i++) {
-        try {
-            StatsGraph graph = run.buildOneDB( ids.get(i).intValue() );
-            if(graph != null) {
-                graphs.add( graph );
-            }
-        } catch (Exception e) {
-            
-        }
+    	
+    	for(int i = 0 ; i < ids.size(); i++) {
+        	try {
+            	StatsGraph graph = run.buildOneDB( ids.get(i).intValue() );
+            	if(graph != null) {
+                	graphs.add( graph );
+            	}
+        	} catch (Exception e) {            
+        	}
+    	}
+	} 	
+} finally {
+	try {
+        	if(con != null) {
+            	con.close();
+        	}
+    } catch(Exception e) {
     }
-    
+}
+
+if( name != null) {
 %>
 <!-- <head> -->
     <script type='text/javascript' src='/dojo/dojo/dojo.js' djConfig='isDebug: false, parseOnLoad: true'>
@@ -128,20 +132,18 @@
 <% 
 try
 {
-for (StatsGraph graph : graphs) 
-{
+	for (StatsGraph graph : graphs) 
+	{
 %>
 <p>
 <div id="<%=graph.getDivName()%>Head" style="background-color: #f2f2f2; border-top: 1px solid #2581c7; margin: 0px; width: 100%; height: 16px;"><div align="left" style="background-color: #f2f2f2; float:left; text-align:left; width:75%; height: 20px;"><%=graph.getName() %></div><div align=right style="background-color: #f2f2f2; float:left; width:25%; text-align:right;"><a href="#" onClick="hide('<%=graph.getDivName()%>');hide('<%=graph.getDivName()%>Sub');"><img border=0 src="/monitoring/images/min-b.png"></a>&nbsp;<a href="#" onClick="show('<%=graph.getDivName()%>');show('<%=graph.getDivName()%>Sub');"><img border=0 src="/monitoring/images/max-b.png"></a></div></div>
 <%=graph.getDivImplement()%>
 </p>
 <%
-}
+	}
 }
 catch (Exception e)
-{
-    
-}
+{}
 %>
 
         </td>



Mime
View raw message