geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ecr...@apache.org
Subject svn commit: r599256 - /geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java
Date Thu, 29 Nov 2007 03:56:52 GMT
Author: ecraig
Date: Wed Nov 28 19:56:51 2007
New Revision: 599256

URL: http://svn.apache.org/viewvc?rev=599256&view=rev
Log:
Modified messages so that they are evident based on color
Cleaned up code in portlet by adding additional methods


Modified:
    geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/MonitoringPortlet.java

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=599256&r1=599255&r2=599256&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 19:56:51 2007
@@ -212,7 +212,9 @@
             String server_id = actionRequest.getParameter("server_id");
             actionResponse.setRenderParameter("message", alterServerState(
                     server_id, true));
-        } else if(action.equals("testAddServerConnection")) {
+        }
+        else if (action.equals("testAddServerConnection"))
+        {
             String name = actionRequest.getParameter("name");
             String ip = actionRequest.getParameter("ip");
             String username = actionRequest.getParameter("username");
@@ -225,7 +227,9 @@
             actionResponse.setRenderParameter("ip", ip);
             actionResponse.setRenderParameter("password", password);
             actionResponse.setRenderParameter("password2", password2);
-        } else if(action.equals("testEditServerConnection")) {
+        }
+        else if (action.equals("testEditServerConnection"))
+        {
             String name = actionRequest.getParameter("name");
             String ip = actionRequest.getParameter("ip");
             String username = actionRequest.getParameter("username");
@@ -245,12 +249,17 @@
         }
     }
 
-    private String testConnection(String name, String ip, String username, String password)
{
-        try {
+    private String testConnection(String name, String ip, String username,
+            String password)
+    {
+        try
+        {
             MRCConnector mrc = new MRCConnector(ip, username, password);
-            return "Connection was successfully established.";
-        } catch(Exception e) {
-            return "Failed to create a connection to server.";
+            return "<font color=\"green\"><strong><li>Connection was successfully
established.</li></strong></font>";
+        }
+        catch (Exception e)
+        {
+            return "<font color=\"red\"><strong><li>Failed to create a
connection to server.</li></strong></font>";
         }
     }
 
@@ -278,24 +287,28 @@
                 stmt
                         .executeUpdate("UPDATE SERVERS SET ENABLED = 0 WHERE SERVER_ID="
                                 + server_id);
-                message = "Server " + name + " was successfully disabled.";
+                message = "<font color=\"green\"><strong><li>Server " +
name
+                        + " was successfully disabled.</li></strong></font>";
             }
             else
             {
                 stmt
                         .executeUpdate("UPDATE SERVERS SET ENABLED = 1 WHERE SERVER_ID="
                                 + server_id);
-                message = "Server " + name + " was successfully enabled.";
+                message = "<font color=\"green\"><strong><li>Server " +
name
+                        + " was successfully enabled.</li></strong></font>";
             }
         }
         catch (SQLException e)
         {
             if (!b)
-                message = "[ERROR] Server with server_id = " + server_id
-                        + " could not be disabled.";
+                message = "<font color=\"red\"><strong><li>[ERROR] Server
with server_id = "
+                        + server_id
+                        + " could not be disabled.</li></strong></font>";
             else
-                message = "[ERROR] Server with server_id = " + server_id
-                        + " could not be enabled.";
+                message = "<font color=\"red\"><strong><li>[ERROR] Server
with server_id = "
+                        + server_id
+                        + " could not be enabled.</li></strong></font>";
         }
         finally
         {
@@ -339,82 +352,9 @@
             request.setAttribute("server_id", server_id);
             String mbean = request.getParameter("mbean");
             request.setAttribute("mbean", mbean);
-            PreparedStatement pStmt = null;
-            ResultSet rs = 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()) {
-                    request.setAttribute("message",
-                            "<font color='red'>DATABASE ERROR: Server id "
-                                    + server_id
-                                    + " not found in database</font>");
-                    viewServer.include(request, response);
-                    return;
-                }
-                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 {
-                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 "
-                                        + server_ip + ": " + e.getMessage()
-                                        + "</font>");
-                viewServer.include(request, response);
-                return;
-            }
-            try
-            {
-                if (mrc.startTrackingMbean(mbean))
-                {
-                    request.setAttribute("message", "<b>MBean " + mbean
-                            + " tracking on server " + rs.getString("name")
-                            + "</b>");
-                    viewServer.include(request, response);
-                }
-                else
-                {
-                    request.setAttribute("message",
-                            "<font color='red'>ERROR: MBean " + mbean
-                                    + " could <b>NOT</b> be tracked on server
"
-                                    + rs.getString("name") + "</font>");
-                    viewServer.include(request, response);
-                    return;
-                }
-
-            }
-            catch (Exception e)
-            {
-                request
-                        .setAttribute(
-                                "message",
-                                "<font color='red'>MRC ERROR: MBean "
-                                        + mbean
-                                        + " could <b>NOT</b> be tracked on server
"
-                                        + server_ip + ": " + e.getMessage()
-                                        + "</font>");
-                viewServer.include(request, response);
-                return;
-            }
+            String message = startTrackingMbean(server_id, mbean);
+            request.setAttribute("message", message);
+            viewServer.include(request, response);
         }
         else if (action.equals("stopTrackingMbean"))
         {
@@ -422,170 +362,16 @@
             request.setAttribute("server_id", server_id);
             String mbean = request.getParameter("mbean");
             request.setAttribute("mbean", mbean);
-            PreparedStatement pStmt = null;
-            ResultSet rs = 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()) {
-                    request.setAttribute("message",
-                            "<font color='red'>DATABASE ERROR: Server id "
-                                    + server_id
-                                    + " not found in database</font>");
-                    viewServer.include(request, response);
-                    return;
-                }
-                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 {
-                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 "
-                                        + server_ip + ": " + e.getMessage()
-                                        + "</font>");
-                viewServer.include(request, response);
-                return;
-            }
-            try
-            {
-                if (mrc.stopTrackingMbean(mbean))
-                {
-                    request.setAttribute("message", "<b>MBean " + mbean
-                            + " removed from tracking on server "
-                            + rs.getString("name") + "</b>");
-                    viewServer.include(request, response);
-                }
-                else
-                {
-                    request
-                            .setAttribute(
-                                    "message",
-                                    "<font color='red'>ERROR: MBean "
-                                            + mbean
-                                            + " could <b>NOT</b> be removed from
tracking on server "
-                                            + rs.getString("name") + "</font>");
-                    viewServer.include(request, response);
-                    return;
-                }
-
-            }
-            catch (Exception e)
-            {
-                request
-                        .setAttribute(
-                                "message",
-                                "<font color='red'>MRC ERROR: MBean "
-                                        + mbean
-                                        + " could <b>NOT</b> be removed from
tracking on server "
-                                        + server_ip + ": " + e.getMessage()
-                                        + "</font>");
-                viewServer.include(request, response);
-                return;
-            }
+            String message = stopTrackingMbean(server_id, mbean);
+            request.setAttribute("message", message);
+            viewServer.include(request, response);
         }
         else if (action.equals("stopThread"))
         {
-            PreparedStatement pStmt = null;
-            ResultSet rs = 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()) {
-                    request.setAttribute("message",
-                            "<font color='red'>DATABASE ERROR: Server id "
-                                    + server_id
-                                    + " not found in database</font>");
-                    normalView.include(request, response);
-                    return;
-                }
-                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 {
-                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 "
-                                        + server_ip + ": " + e.getMessage()
-                                        + "</font>");
-                normalView.include(request, response);
-                return;
-            }
-            try
-            {
-                if (mrc.stopSnapshotThread())
-                {
-                    request.setAttribute("message",
-                            "<b>Snapshot thread stopped on server "
-                                    + rs.getString("name") + "</b>");
-                    normalView.include(request, response);
-                }
-                else
-                {
-                    request
-                            .setAttribute(
-                                    "message",
-                                    "<font color='red'>ERROR: Snapshot thread could
<b>NOT</b> be stopped on server "
-                                            + rs.getString("name") + "</font>");
-                    normalView.include(request, response);
-                    return;
-                }
-
-            }
-            catch (Exception e)
-            {
-                request
-                        .setAttribute(
-                                "message",
-                                "<font color='red'>MRC ERROR: Snapshot thread could
<b>NOT</b> be stopped on server "
-                                        + server_ip
-                                        + ": "
-                                        + e.getMessage()
-                                        + "</font>");
-                normalView.include(request, response);
-                return;
-            }
+            String message = stopThread(server_id);
+            request.setAttribute("message", message);
+            normalView.include(request, response);
 
         }
         else if (action.equals("startThread"))
@@ -593,85 +379,13 @@
             String server_id = request.getParameter("server_id");
             Long snapshotDuration = java.lang.Long.parseLong(request
                     .getParameter("snapshotDuration"));
-            PreparedStatement pStmt = null;
-            ResultSet rs = 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()) {
-                    request.setAttribute("message",
-                            "<font color='red'>DATABASE ERROR: Server id "
-                                    + server_id
-                                    + " not found in database</font>");
-                    normalView.include(request, response);
-                    return;
-                }
-                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 {
-                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 "
-                                        + server_ip + ": " + e.getMessage()
-                                        + "</font>");
-                normalView.include(request, response);
-                return;
-            }
-            try
-            {
-
-                if (mrc.startSnapshotThread(new Long(snapshotDuration))) {
-                    request.setAttribute("message",
-                            "<b>Snapshot thread started on server "
-                                    + rs.getString("name") + "</b>");
-                    normalView.include(request, response);
-                } else {
-                    request
-                            .setAttribute(
-                                    "message",
-                                    "<font color='red'>ERROR: Snapshot thread could
<b>NOT</b> be started on server "
-                                            + rs.getString("name") + "</font>");
-                    normalView.include(request, response);
-                    return;
-                }
-
-            }
-            catch (Exception e)
-            {
-                request
-                        .setAttribute(
-                                "message",
-                                "<font color='red'>MRC ERROR: Snapshot thread could
<b>NOT</b> be started on server "
-                                        + server_ip
-                                        + ": "
-                                        + e.getMessage()
-                                        + "</font>");
-                normalView.include(request, response);
-                return;
-            }
+            String message = startThread(server_id, snapshotDuration);
+            request.setAttribute("message", message);
+            normalView.include(request, response);
 
-        } else {
+        }
+        else
+        {
             request.setAttribute("message", request.getParameter("message"));
             normalView.include(request, response);
         }
@@ -785,25 +499,37 @@
             String message = request.getParameter("message");
             request.setAttribute("message", message);
             normalView.include(request, response);
-        } else if(action.equals("testAddServerConnection")) {
+        }
+        else if (action.equals("testAddServerConnection"))
+        {
             request.setAttribute("name", request.getParameter("name"));
             request.setAttribute("ip", request.getParameter("ip"));
             request.setAttribute("username", request.getParameter("username"));
             request.setAttribute("password", request.getParameter("password"));
-            request.setAttribute("password2", request.getParameter("password2"));
+            request
+                    .setAttribute("password2", request
+                            .getParameter("password2"));
             request.setAttribute("message", request.getParameter("message"));
             addServer.include(request, response);
-        }  else if(action.equals("testEditServerConnection")) {
+        }
+        else if (action.equals("testEditServerConnection"))
+        {
             request.setAttribute("name", request.getParameter("name"));
             request.setAttribute("ip", request.getParameter("ip"));
             request.setAttribute("username", request.getParameter("username"));
             request.setAttribute("password", request.getParameter("password"));
-            request.setAttribute("password2", request.getParameter("password2"));
+            request
+                    .setAttribute("password2", request
+                            .getParameter("password2"));
             request.setAttribute("message", request.getParameter("message"));
-            request.setAttribute("server_id", request.getParameter("server_id"));
+            request
+                    .setAttribute("server_id", request
+                            .getParameter("server_id"));
             request.setAttribute("snapshot", request.getParameter("snapshot"));
             editServer.include(request, response);
-        } else {
+        }
+        else
+        {
             editNormalView.include(request, response);
         }
     }
@@ -907,7 +633,8 @@
     }
 
     private void updateServer(ActionRequest actionRequest,
-            ActionResponse actionResponse) {
+            ActionResponse actionResponse)
+    {
         String server_id = actionRequest.getParameter("server_id");
         actionResponse.setRenderParameter("server_id", server_id);
         DBManager DBase = new DBManager();
@@ -917,10 +644,13 @@
         String password = actionRequest.getParameter("password");
         String username = actionRequest.getParameter("username");
         String snapshot = actionRequest.getParameter("snapshot");
-        try {
+        try
+        {
             // update the client side db (table = SERVERS)
-            if (password.equals("")) {
-                PreparedStatement pStmt = con.prepareStatement("UPDATE servers SET name='"
+            if (password.equals(""))
+            {
+                PreparedStatement pStmt = con
+                        .prepareStatement("UPDATE servers SET name='"
                                 + name
                                 + "', ip='"
                                 + ip
@@ -929,8 +659,11 @@
                                 + "', modified=CURRENT_TIMESTAMP, last_seen=CURRENT_TIMESTAMP
WHERE server_id="
                                 + server_id);
                 pStmt.executeUpdate();
-            } else {
-                PreparedStatement pStmt = con.prepareStatement("UPDATE servers SET name='"
+            }
+            else
+            {
+                PreparedStatement pStmt = con
+                        .prepareStatement("UPDATE servers SET name='"
                                 + name
                                 + "', ip='"
                                 + ip
@@ -944,14 +677,17 @@
             }
             con.close();
             // update the server side db
-            (new MRCConnector(ip, username, password)).setSnapshotDuration(Long.parseLong(snapshot)
* 1000 * 60);
+            (new MRCConnector(ip, username, password)).setSnapshotDuration(Long
+                    .parseLong(snapshot) * 1000 * 60);
             // set success message
-            actionResponse.setRenderParameter(
+            actionResponse
+                    .setRenderParameter(
                             "message",
                             "<font color=\"green\"><strong><li>Server has
been updated</li></strong></font>");
-        } catch (Exception e) {
-            actionResponse.setRenderParameter(
-                    "message",
+        }
+        catch (Exception e)
+        {
+            actionResponse.setRenderParameter("message",
                     "<font color=\"red\"><strong><li>Error updating server</li></strong></font>"
                             + e.getMessage());
         }
@@ -1235,6 +971,283 @@
                     "<font color=\"red\"><strong><li>Error deleting graph</li></strong></font>"
                             + e.getMessage());
             return;
+        }
+    }
+
+    private String startTrackingMbean(String server_id, String mbean)
+    {
+        PreparedStatement pStmt = null;
+        ResultSet rs = 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())
+            {
+                return "<font color=\"red\"><strong><li>DATABASE ERROR:
Server id "
+                        + server_id
+                        + " not found in database</li></strong></font>";
+            }
+            server_ip = rs.getString("ip");
+            password = rs.getString("password");
+            username = rs.getString("username");
+        }
+        catch (SQLException e)
+        {
+            return "<font color=\"red\"><strong><li>DATABASE ERROR: "
+                    + e.getMessage() + "</li></strong></font>";
+        }
+        try
+        {
+            con.close();
+            mrc = new MRCConnector(server_ip, username, password);
+        }
+        catch (Exception e)
+        {
+            return "<font color=\"red\"><strong><li>MRC ERROR: Unable to
connect to server "
+                    + server_ip
+                    + ": "
+                    + e.getMessage()
+                    + "</li></strong></font>";
+        }
+        try
+        {
+            if (mrc.startTrackingMbean(mbean))
+            {
+                String mbarr[] = mbean.split("name=");
+                return "<font color=\"green\"><strong><li>MBean " + mbarr[1]
+                        + " tracking on server " + rs.getString("name")
+                        + "</li></strong></font>";
+            }
+            else
+            {
+                String mbarr[] = mbean.split("name=");
+                return "<font color=\"red\"><strong><li>ERROR: MBean "
+                        + mbarr[1] + " could <b>NOT</b> be tracked on server
"
+                        + rs.getString("name") + "</li></strong></font>";
+            }
+
+        }
+        catch (Exception e)
+        {
+            return "<font color=\"red\"><strong><li>MRC ERROR: MBean "
+ mbean
+                    + " could <b>NOT</b> be tracked on server " + server_ip
+                    + ": " + e.getMessage() + "</li></strong></font>";
+        }
+    }
+
+    private String stopTrackingMbean(String server_id, String mbean)
+    {
+        PreparedStatement pStmt = null;
+        ResultSet rs = 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())
+            {
+                return "<font color=\"red\"><strong><li>DATABASE ERROR:
Server id "
+                        + server_id
+                        + " not found in database</li></strong></font>";
+            }
+            server_ip = rs.getString("ip");
+            password = rs.getString("password");
+            username = rs.getString("username");
+        }
+        catch (SQLException e)
+        {
+            return "<font color=\"red\"><strong><li>DATABASE ERROR: "
+                    + e.getMessage() + "</li></strong></font>";
+        }
+        try
+        {
+            con.close();
+            mrc = new MRCConnector(server_ip, username, password);
+        }
+        catch (Exception e)
+        {
+            return "<font color=\"red\"><strong><li>MRC ERROR: Unable to
connect to server "
+                    + server_ip
+                    + ": "
+                    + e.getMessage()
+                    + "</li></strong></font>";
+        }
+        try
+        {
+            if (mrc.stopTrackingMbean(mbean))
+            {
+                String mbarr[] = mbean.split("name=");
+                return "<font color=\"green\"><strong><li>MBean " + mbarr[1]
+                        + " removed from tracking on server "
+                        + rs.getString("name") + "</li></strong></font>";
+            }
+            else
+            {
+                String mbarr[] = mbean.split("name=");
+                return "<font color=\"red\"><strong><li>ERROR: MBean "
+                        + mbarr[1]
+                        + " could <b>NOT</b> be removed from tracking on server
"
+                        + rs.getString("name") + "</li></strong></font>";
+            }
+
+        }
+        catch (Exception e)
+        {
+            return "<font color=\"red\"><strong><li>MRC ERROR: MBean "
+ mbean
+                    + " could <b>NOT</b> be removed from tracking on server "
+                    + server_ip + ": " + e.getMessage()
+                    + "</li></strong></font>";
+        }
+    }
+
+    private String stopThread(String server_id)
+    {
+        PreparedStatement pStmt = null;
+        ResultSet rs = 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())
+            {
+                return "<font color=\"red\"><strong><li>DATABASE ERROR:
Server id "
+                        + server_id
+                        + " not found in database</li></strong></font>";
+            }
+            server_ip = rs.getString("ip");
+            password = rs.getString("password");
+            username = rs.getString("username");
+        }
+        catch (SQLException e)
+        {
+            return "<font color=\"red\"><strong><li>DATABASE ERROR: "
+                    + e.getMessage() + "</li></strong></font>";
+        }
+        try
+        {
+            con.close();
+            mrc = new MRCConnector(server_ip, username, password);
+        }
+        catch (Exception e)
+        {
+            return "<font color=\"red\"><strong><li>MRC ERROR: Unable to
connect to server "
+                    + server_ip
+                    + ": "
+                    + e.getMessage()
+                    + "</li></strong></font>";
+        }
+        try
+        {
+            if (mrc.stopSnapshotThread())
+                return "<font color=\"green\"><strong><li>Snapshot thread
stopped on server "
+                        + rs.getString("name") + "</li></strong></font>";
+            else
+            {
+                return "<font color=\"red\"><strong><li>ERROR: Snapshot
thread could <b>NOT</b> be stopped on server "
+                        + rs.getString("name") + "</li></strong></font>";
+            }
+
+        }
+        catch (Exception e)
+        {
+            return "<font color=\"red\"><strong><li>MRC ERROR: Snapshot
thread could <b>NOT</b> be stopped on server "
+                    + server_ip
+                    + ": "
+                    + e.getMessage()
+                    + "</li></strong></font>";
+        }
+    }
+
+    private String startThread(String server_id, Long snapshotDuration)
+    {
+        PreparedStatement pStmt = null;
+        ResultSet rs = 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())
+            {
+                return "<font color=\"red\"><strong><li>DATABASE ERROR:
Server id "
+                        + server_id
+                        + " not found in database</li></strong></font>";
+            }
+            server_ip = rs.getString("ip");
+            password = rs.getString("password");
+            username = rs.getString("username");
+        }
+        catch (SQLException e)
+        {
+            return "<font color=\"red\"><strong><li>DATABASE ERROR: "
+                    + e.getMessage() + "</li></strong></font>";
+        }
+        try
+        {
+            con.close();
+            mrc = new MRCConnector(server_ip, username, password);
+        }
+        catch (Exception e)
+        {
+            return "<font color=\"red\"><strong><li>MRC ERROR: Unable to
connect to server "
+                    + server_ip
+                    + ": "
+                    + e.getMessage()
+                    + "</li></strong></font>";
+        }
+        try
+        {
+
+            if (mrc.startSnapshotThread(new Long(snapshotDuration)))
+            {
+                return "<font color=\"green\"><strong><li>Snapshot thread
started on server "
+                        + rs.getString("name") + "</li></strong></font>";
+            }
+            else
+            {
+                return "<font color=\"red\"><strong><li>ERROR: Snapshot
thread could <b>NOT</b> be started on server "
+                        + rs.getString("name") + "</li></strong></font>";
+            }
+
+        }
+        catch (Exception e)
+        {
+            return "<font color=\"red\"><strong><li>MRC ERROR: Snapshot
thread could <b>NOT</b> be started on server "
+                    + server_ip
+                    + ": "
+                    + e.getMessage()
+                    + "</li></strong></font>";
         }
     }
 



Mime
View raw message