Source Code Cross Referenced for MonitoringPortlet.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » monitoring » console » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » plugins » org.apache.geronimo.monitoring.console 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */package org.apache.geronimo.monitoring.console;
0017:
0018:        import java.io.IOException;
0019:        import java.sql.Connection;
0020:        import java.sql.PreparedStatement;
0021:        import java.sql.ResultSet;
0022:        import java.sql.SQLException;
0023:        import java.sql.Statement;
0024:
0025:        import javax.portlet.ActionRequest;
0026:        import javax.portlet.ActionResponse;
0027:        import javax.portlet.GenericPortlet;
0028:        import javax.portlet.PortletConfig;
0029:        import javax.portlet.PortletException;
0030:        import javax.portlet.PortletRequestDispatcher;
0031:        import javax.portlet.RenderRequest;
0032:        import javax.portlet.RenderResponse;
0033:
0034:        import org.apache.geronimo.monitoring.console.util.DBManager;
0035:        import org.apache.geronimo.crypto.EncryptionManager;
0036:
0037:        /**
0038:         * STATS
0039:         */
0040:        public class MonitoringPortlet extends GenericPortlet {
0041:
0042:            private static final String NORMALVIEW_JSP = "/WEB-INF/view/monitoringNormal.jsp";
0043:
0044:            private static final String VIEWVIEWS_JSP = "/WEB-INF/view/monitoringViews.jsp";
0045:
0046:            private static final String VIEWSERVERS_JSP = "/WEB-INF/view/monitoringServers.jsp";
0047:
0048:            private static final String VIEWGRAPHS_JSP = "/WEB-INF/view/monitoringGraphs.jsp";
0049:
0050:            private static final String PAGEVIEW_JSP = "/WEB-INF/view/monitoringPage.jsp";
0051:
0052:            private static final String EDITVIEW_JSP = "/WEB-INF/view/monitoringEditView.jsp";
0053:
0054:            private static final String ADDVIEW_JSP = "/WEB-INF/view/monitoringAddView.jsp";
0055:
0056:            private static final String ADDGRAPH_JSP = "/WEB-INF/view/monitoringAddGraph.jsp";
0057:
0058:            private static final String EDITGRAPH_JSP = "/WEB-INF/view/monitoringEditGraph.jsp";
0059:
0060:            private static final String VIEWSERVER_JSP = "/WEB-INF/view/monitoringViewServer.jsp";
0061:
0062:            private static final String EDITSERVER_JSP = "/WEB-INF/view/monitoringEditServer.jsp";
0063:
0064:            private static final String ADDSERVER_JSP = "/WEB-INF/view/monitoringAddServer.jsp";
0065:
0066:            private static final String HELPVIEW_JSP = "/WEB-INF/view/monitoringHelp.jsp";
0067:
0068:            private static final String EDITNORMALVIEW_JSP = "/WEB-INF/view/monitoringEdit.jsp";
0069:
0070:            private PortletRequestDispatcher normalView;
0071:
0072:            private PortletRequestDispatcher viewViews;
0073:
0074:            private PortletRequestDispatcher viewServers;
0075:
0076:            private PortletRequestDispatcher viewGraphs;
0077:
0078:            private PortletRequestDispatcher pageView;
0079:
0080:            private PortletRequestDispatcher editView;
0081:
0082:            private PortletRequestDispatcher addView;
0083:
0084:            private PortletRequestDispatcher addGraph;
0085:
0086:            private PortletRequestDispatcher editGraph;
0087:
0088:            private PortletRequestDispatcher viewServer;
0089:
0090:            private PortletRequestDispatcher editServer;
0091:
0092:            private PortletRequestDispatcher addServer;
0093:
0094:            private PortletRequestDispatcher helpView;
0095:
0096:            private PortletRequestDispatcher editNormalView;
0097:
0098:            @Override
0099:            public void processAction(ActionRequest actionRequest,
0100:                    ActionResponse actionResponse) throws PortletException,
0101:                    IOException {
0102:                String action = actionRequest.getParameter("action");
0103:                actionResponse.setRenderParameter("action", action);
0104:                if (action.equals("showView")) {
0105:                    String view_id = actionRequest.getParameter("view_id");
0106:                    actionResponse.setRenderParameter("view_id", view_id);
0107:                } else if (action.equals("showAllViews")) {
0108:                    // no parameters needed to be redirected to doView()
0109:                } else if (action.equals("showAllServers")) {
0110:                    // no parameters needed to be redirected to doView()
0111:                } else if (action.equals("showAllGraphs")) {
0112:                    // no parameters needed to be redirected to doView()
0113:                } else if (action.equals("showEditView")) {
0114:                    String view_id = actionRequest.getParameter("view_id");
0115:                    actionResponse.setRenderParameter("view_id", view_id);
0116:                } else if (action.equals("saveEditView")) {
0117:                    updateView(actionRequest, actionResponse);
0118:                } else if (action.equals("showAddView")) {
0119:                    // no parameters needed to be redirected to doView()
0120:                } else if (action.equals("saveAddView")) {
0121:                    addView(actionRequest, actionResponse);
0122:                } else if (action.equals("showAddGraph")) {
0123:                    String server_id = actionRequest.getParameter("server_id");
0124:                    if (server_id != null)
0125:                        actionResponse.setRenderParameter("server_id",
0126:                                server_id);
0127:
0128:                    String mbean = actionRequest.getParameter("mbean");
0129:                    if (mbean != null)
0130:                        actionResponse.setRenderParameter("mbean", mbean);
0131:
0132:                    String dataname = actionRequest.getParameter("dataname");
0133:                    if (dataname != null)
0134:                        actionResponse.setRenderParameter("dataname", dataname);
0135:                } else if (action.equals("saveAddGraph")) {
0136:                    addGraph(actionRequest, actionResponse);
0137:                } else if (action.equals("showEditGraph")) {
0138:                    String graph_id = actionRequest.getParameter("graph_id");
0139:                    actionResponse.setRenderParameter("graph_id", graph_id);
0140:                } else if (action.equals("saveEditGraph")) {
0141:                    updateGraph(actionRequest, actionResponse);
0142:                } else if (action.equals("deleteGraph")) {
0143:                    deleteGraph(actionRequest, actionResponse);
0144:                } else if (action.equals("deleteView")) {
0145:                    deleteView(actionRequest, actionResponse);
0146:                } else if (action.equals("showServer")) {
0147:                    String server_id = actionRequest.getParameter("server_id");
0148:                    actionResponse.setRenderParameter("server_id", server_id);
0149:                } else if (action.equals("showEditServer")) {
0150:                    String server_id = actionRequest.getParameter("server_id");
0151:                    actionResponse.setRenderParameter("server_id", server_id);
0152:                } else if (action.equals("saveEditServer")) {
0153:                    updateServer(actionRequest, actionResponse);
0154:                } else if (action.equals("showAddServer")) {
0155:                    // no parameters needed to be redirected to doView()
0156:                } else if (action.equals("deleteServer")) {
0157:                    deleteServer(actionRequest, actionResponse);
0158:                } else if (action.equals("saveAddServer")) {
0159:                    addServer(actionRequest, actionResponse);
0160:                } else if (action.equals("startTrackingMbean")) {
0161:                    String server_id = actionRequest.getParameter("server_id");
0162:                    actionResponse.setRenderParameter("server_id", server_id);
0163:                    String mbean = actionRequest.getParameter("mbean");
0164:                    actionResponse.setRenderParameter("mbean", mbean);
0165:                } else if (action.equals("stopTrackingMbean")) {
0166:                    String server_id = actionRequest.getParameter("server_id");
0167:                    actionResponse.setRenderParameter("server_id", server_id);
0168:                    String mbean = actionRequest.getParameter("mbean");
0169:                    actionResponse.setRenderParameter("mbean", mbean);
0170:                } else if (action.equals("stopThread")
0171:                        || action.equals("disableServerViewQuery")) {
0172:                    String server_id = actionRequest.getParameter("server_id");
0173:                    String message = stopThread(server_id);
0174:                    actionResponse.setRenderParameter("server_id", server_id);
0175:                    actionResponse.setRenderParameter("message", message);
0176:                } else if (action.equals("startThread")
0177:                        || action.equals("enableServerViewQuery")) {
0178:                    String server_id = actionRequest.getParameter("server_id");
0179:                    String snapshotDuration = actionRequest
0180:                            .getParameter("snapshotDuration");
0181:                    String message = startThread(server_id, new Long(
0182:                            snapshotDuration));
0183:                    actionResponse.setRenderParameter("message", message);
0184:                    actionResponse.setRenderParameter("server_id", server_id);
0185:                    actionResponse.setRenderParameter("snapshotDuration",
0186:                            snapshotDuration);
0187:                } else if (action.equals("disableServer")
0188:                        || action.equals("disableEditServer")) {
0189:                    String server_id = actionRequest.getParameter("server_id");
0190:                    actionResponse.setRenderParameter("server_id", server_id);
0191:                    ;
0192:                    actionResponse.setRenderParameter("message",
0193:                            alterServerState(server_id, false));
0194:                } else if (action.equals("enableServer")
0195:                        || action.equals("enableEditServer")) {
0196:                    String server_id = actionRequest.getParameter("server_id");
0197:                    actionResponse.setRenderParameter("message",
0198:                            alterServerState(server_id, true));
0199:                    actionResponse.setRenderParameter("server_id", server_id);
0200:                    ;
0201:                } else if (action.equals("testAddServerConnection")) {
0202:                    String name = actionRequest.getParameter("name");
0203:                    String ip = actionRequest.getParameter("ip");
0204:                    String username = actionRequest.getParameter("username");
0205:                    String password = actionRequest.getParameter("password");
0206:                    String password2 = actionRequest.getParameter("password2");
0207:                    Integer port = Integer.parseInt(actionRequest
0208:                            .getParameter("port"));
0209:                    Integer protocol = Integer.parseInt(actionRequest
0210:                            .getParameter("protocol"));
0211:                    String message = testConnection(name, ip, username,
0212:                            password, port, protocol);
0213:                    actionResponse.setRenderParameter("message", message);
0214:                    actionResponse.setRenderParameter("name", name);
0215:                    actionResponse.setRenderParameter("username", username);
0216:                    actionResponse.setRenderParameter("ip", ip);
0217:                    actionResponse.setRenderParameter("password", password);
0218:                    actionResponse.setRenderParameter("password2", password2);
0219:                    actionResponse.setRenderParameter("port", "" + port);
0220:                    actionResponse
0221:                            .setRenderParameter("protocol", "" + protocol);
0222:                } else if (action.equals("testEditServerConnection")) {
0223:                    String name = actionRequest.getParameter("name");
0224:                    String ip = actionRequest.getParameter("ip");
0225:                    String username = actionRequest.getParameter("username");
0226:                    String password = actionRequest.getParameter("password");
0227:                    String password2 = actionRequest.getParameter("password2");
0228:                    String server_id = actionRequest.getParameter("server_id");
0229:                    String snapshot = actionRequest.getParameter("snapshot");
0230:                    String retention = actionRequest.getParameter("retention");
0231:                    Integer port = Integer.parseInt(actionRequest
0232:                            .getParameter("port"));
0233:                    Integer protocol = Integer.parseInt(actionRequest
0234:                            .getParameter("protocol"));
0235:                    String message = testConnection(name, ip, username,
0236:                            password, port, protocol);
0237:                    actionResponse.setRenderParameter("message", message);
0238:                    actionResponse.setRenderParameter("name", name);
0239:                    actionResponse.setRenderParameter("username", username);
0240:                    actionResponse.setRenderParameter("ip", ip);
0241:                    actionResponse.setRenderParameter("password", password);
0242:                    actionResponse.setRenderParameter("password2", password2);
0243:                    actionResponse.setRenderParameter("snapshot", snapshot);
0244:                    actionResponse.setRenderParameter("server_id", server_id);
0245:                    actionResponse.setRenderParameter("retention", retention);
0246:                    actionResponse.setRenderParameter("port", "" + port);
0247:                    actionResponse
0248:                            .setRenderParameter("protocol", "" + protocol);
0249:                }
0250:            }
0251:
0252:            private String testConnection(String name, String ip,
0253:                    String username, String password, int port, int protocol) {
0254:                try {
0255:                    MRCConnector mrc = new MRCConnector(ip, username, password,
0256:                            port, protocol);
0257:
0258:                    return "<font color=\"green\"><strong><li>Connection was successfully established.</li></strong></font>";
0259:                } catch (Exception e) {
0260:                    return "<font color=\"red\"><strong><li>Failed to create a connection to server.</li></strong></font>";
0261:                }
0262:            }
0263:
0264:            private String alterServerState(String server_id, boolean b) {
0265:                Connection conn = (new DBManager()).getConnection();
0266:                String message = "";
0267:                String name = "";
0268:                try {
0269:                    PreparedStatement pStmt = conn
0270:                            .prepareStatement("SELECT * FROM servers WHERE server_id="
0271:                                    + server_id);
0272:                    ResultSet rs = pStmt.executeQuery();
0273:                    if (rs.next()) {
0274:                        name = rs.getString("name");
0275:                    }
0276:                    rs.close();
0277:                    conn.close();
0278:                    conn = (new DBManager()).getConnection();
0279:                    Statement stmt = conn.createStatement();
0280:                    if (!b) {
0281:                        stmt
0282:                                .executeUpdate("UPDATE SERVERS SET ENABLED = 0 WHERE SERVER_ID="
0283:                                        + server_id);
0284:                        stmt
0285:                                .executeUpdate("UPDATE GRAPHS SET ENABLED = 0 WHERE SERVER_ID="
0286:                                        + server_id);
0287:                        message = "<font color=\"green\"><strong><li>Server "
0288:                                + name
0289:                                + " was successfully disabled.</li></strong></font>";
0290:                    } else {
0291:                        stmt
0292:                                .executeUpdate("UPDATE SERVERS SET ENABLED = 1 WHERE SERVER_ID="
0293:                                        + server_id);
0294:                        stmt
0295:                                .executeUpdate("UPDATE GRAPHS SET ENABLED = 1 WHERE SERVER_ID="
0296:                                        + server_id);
0297:                        message = "<font color=\"green\"><strong><li>Server "
0298:                                + name
0299:                                + " was successfully enabled.</li></strong></font>";
0300:                    }
0301:                } catch (SQLException e) {
0302:                    if (!b)
0303:                        message = "<font color=\"red\"><strong><li>[ERROR] Server with server_id = "
0304:                                + server_id
0305:                                + " could not be disabled.</li></strong></font>";
0306:                    else
0307:                        message = "<font color=\"red\"><strong><li>[ERROR] Server with server_id = "
0308:                                + server_id
0309:                                + " could not be enabled.</li></strong></font>";
0310:                } finally {
0311:                    if (conn != null) {
0312:                        try {
0313:                            conn.close();
0314:                        } catch (Exception e) {
0315:
0316:                        }
0317:                    }
0318:                }
0319:                return message;
0320:            }
0321:
0322:            @Override
0323:            public void doView(RenderRequest request, RenderResponse response)
0324:                    throws PortletException, IOException {
0325:                String action = request.getParameter("action");
0326:                if (action == null)
0327:                    action = "showNormal";
0328:                if (action.equals("showView")) {
0329:                    String view_id = request.getParameter("view_id");
0330:                    request.setAttribute("view_id", view_id);
0331:                    pageView.include(request, response);
0332:                } else if (action.equals("showAllViews")) {
0333:                    request.setAttribute("message", "");
0334:                    viewViews.include(request, response);
0335:                } else if (action.equals("showAllServers")) {
0336:                    request.setAttribute("message", "");
0337:                    viewServers.include(request, response);
0338:                } else if (action.equals("showAllGraphs")) {
0339:                    request.setAttribute("message", "");
0340:                    viewGraphs.include(request, response);
0341:                } else if (action.equals("showServer")) {
0342:                    String server_id = request.getParameter("server_id");
0343:                    request.setAttribute("server_id", server_id);
0344:                    viewServer.include(request, response);
0345:                } else if (action.equals("startTrackingMbean")) {
0346:                    String server_id = request.getParameter("server_id");
0347:                    request.setAttribute("server_id", server_id);
0348:                    String mbean = request.getParameter("mbean");
0349:                    request.setAttribute("mbean", mbean);
0350:                    String message = startTrackingMbean(server_id, mbean);
0351:                    request.setAttribute("message", message);
0352:                    viewServer.include(request, response);
0353:                } else if (action.equals("stopTrackingMbean")) {
0354:                    String server_id = request.getParameter("server_id");
0355:                    request.setAttribute("server_id", server_id);
0356:                    String mbean = request.getParameter("mbean");
0357:                    request.setAttribute("mbean", mbean);
0358:                    String message = stopTrackingMbean(server_id, mbean);
0359:                    request.setAttribute("message", message);
0360:                    viewServer.include(request, response);
0361:                } else if (action.equals("stopThread")) {
0362:                    String server_id = request.getParameter("server_id");
0363:                    String message = request.getParameter("message");
0364:                    request.setAttribute("message", message);
0365:                    normalView.include(request, response);
0366:                } else if (action.equals("startThread")) {
0367:                    String server_id = request.getParameter("server_id");
0368:                    Long snapshotDuration = java.lang.Long.parseLong(request
0369:                            .getParameter("snapshotDuration"));
0370:                    String message = request.getParameter("message");
0371:                    request.setAttribute("message", message);
0372:                    normalView.include(request, response);
0373:                } else if (action.equals("disableServerViewQuery")
0374:                        || action.equals("enableServerViewQuery")) {
0375:                    String server_id = request.getParameter("server_id");
0376:                    String message = request.getParameter("message");
0377:                    request.setAttribute("message", message);
0378:                    request.setAttribute("server_id", server_id);
0379:                    viewServer.include(request, response);
0380:                } else {
0381:                    request.setAttribute("message", request
0382:                            .getParameter("message"));
0383:                    normalView.include(request, response);
0384:                }
0385:            }
0386:
0387:            @Override
0388:            protected void doHelp(RenderRequest renderRequest,
0389:                    RenderResponse renderResponse) throws PortletException,
0390:                    IOException {
0391:                helpView.include(renderRequest, renderResponse);
0392:            }
0393:
0394:            @Override
0395:            protected void doEdit(RenderRequest request, RenderResponse response)
0396:                    throws PortletException, IOException {
0397:                String action = request.getParameter("action");
0398:                if (action == null)
0399:                    action = "showNormal";
0400:                if (action.equals("showEditView")) {
0401:                    String view_id = request.getParameter("view_id");
0402:                    request.setAttribute("view_id", view_id);
0403:                    editView.include(request, response);
0404:                } else if (action.equals("saveEditView")) {
0405:                    String view_id = request.getParameter("view_id");
0406:                    request.setAttribute("view_id", view_id);
0407:                    String message = request.getParameter("message");
0408:                    request.setAttribute("message", message);
0409:                    editView.include(request, response);
0410:                } else if (action.equals("showAddView")) {
0411:                    addView.include(request, response);
0412:                } else if (action.equals("saveAddView")) {
0413:                    String message = request.getParameter("message");
0414:                    request.setAttribute("message", message);
0415:                    normalView.include(request, response);
0416:                } else if (action.equals("showAddGraph")) {
0417:                    String server_id = request.getParameter("server_id");
0418:                    request.setAttribute("server_id", server_id);
0419:                    String mbean = request.getParameter("mbean");
0420:                    request.setAttribute("mbean", mbean);
0421:                    String dataname = request.getParameter("dataname");
0422:                    request.setAttribute("dataname", dataname);
0423:                    addGraph.include(request, response);
0424:                } else if (action.equals("saveAddGraph")) {
0425:                    String message = request.getParameter("message");
0426:                    request.setAttribute("message", message);
0427:                    normalView.include(request, response);
0428:                } else if (action.equals("showEditGraph")) {
0429:                    String graph_id = request.getParameter("graph_id");
0430:                    request.setAttribute("graph_id", graph_id);
0431:                    editGraph.include(request, response);
0432:                } else if (action.equals("saveEditGraph")) {
0433:                    String graph_id = request.getParameter("graph_id");
0434:                    request.setAttribute("graph_id", graph_id);
0435:                    String message = request.getParameter("message");
0436:                    request.setAttribute("message", message);
0437:                    editGraph.include(request, response);
0438:                } else if (action.equals("deleteGraph")) {
0439:                    String message = request.getParameter("message");
0440:                    request.setAttribute("message", message);
0441:                    normalView.include(request, response);
0442:                } else if (action.equals("deleteView")) {
0443:                    String message = request.getParameter("message");
0444:                    request.setAttribute("message", message);
0445:                    normalView.include(request, response);
0446:                } else if (action.equals("showEditServer")) {
0447:                    String server_id = request.getParameter("server_id");
0448:                    request.setAttribute("server_id", server_id);
0449:                    editServer.include(request, response);
0450:                } else if (action.equals("saveEditServer")) {
0451:                    String server_id = request.getParameter("server_id");
0452:                    request.setAttribute("server_id", server_id);
0453:                    String message = request.getParameter("message");
0454:                    request.setAttribute("message", message);
0455:                    editServer.include(request, response);
0456:                } else if (action.equals("showAddServer")) {
0457:                    addServer.include(request, response);
0458:                } else if (action.equals("saveAddServer")) {
0459:                    String message = request.getParameter("message");
0460:                    request.setAttribute("message", message);
0461:                    normalView.include(request, response);
0462:                } else if (action.equals("deleteServer")) {
0463:                    String message = request.getParameter("message");
0464:                    request.setAttribute("message", message);
0465:                    normalView.include(request, response);
0466:                } else if (action.equals("testAddServerConnection")) {
0467:                    request.setAttribute("name", request.getParameter("name"));
0468:                    request.setAttribute("ip", request.getParameter("ip"));
0469:                    request.setAttribute("username", request
0470:                            .getParameter("username"));
0471:                    request.setAttribute("password", request
0472:                            .getParameter("password"));
0473:                    request.setAttribute("password2", request
0474:                            .getParameter("password2"));
0475:                    request.setAttribute("message", request
0476:                            .getParameter("message"));
0477:                    request.setAttribute("port", request.getParameter("port"));
0478:                    addServer.include(request, response);
0479:                } else if (action.equals("testEditServerConnection")) {
0480:                    request.setAttribute("name", request.getParameter("name"));
0481:                    request.setAttribute("ip", request.getParameter("ip"));
0482:                    request.setAttribute("port", request.getParameter("port"));
0483:                    request.setAttribute("username", request
0484:                            .getParameter("username"));
0485:                    request.setAttribute("password", request
0486:                            .getParameter("password"));
0487:                    request.setAttribute("password2", request
0488:                            .getParameter("password2"));
0489:                    request.setAttribute("message", request
0490:                            .getParameter("message"));
0491:                    request.setAttribute("server_id", request
0492:                            .getParameter("server_id"));
0493:                    request.setAttribute("snapshot", request
0494:                            .getParameter("snapshot"));
0495:                    request.setAttribute("retention", request
0496:                            .getParameter("retention"));
0497:                    editServer.include(request, response);
0498:                } else if (action.equals("disableEditServer")
0499:                        || action.equals("enableEditServer")) {
0500:                    request.setAttribute("message", request
0501:                            .getParameter("message"));
0502:                    request.setAttribute("server_id", request
0503:                            .getParameter("server_id"));
0504:                    editServer.include(request, response);
0505:                } else if (action.equals("disableServer")
0506:                        || action.equals("enableServer")) {
0507:                    request.setAttribute("message", request
0508:                            .getParameter("message"));
0509:                    request.setAttribute("server_id", request
0510:                            .getParameter("server_id"));
0511:                    normalView.include(request, response);
0512:                } else {
0513:                    normalView.include(request, response);
0514:                }
0515:            }
0516:
0517:            private void updateView(ActionRequest actionRequest,
0518:                    ActionResponse actionResponse) {
0519:                String view_id = actionRequest.getParameter("view_id");
0520:                actionResponse.setRenderParameter("view_id", view_id);
0521:                DBManager DBase = new DBManager();
0522:                Connection con = DBase.getConnection();
0523:                String name = actionRequest.getParameter("name");
0524:                String description = actionRequest.getParameter("description");
0525:                String[] graphsArray = actionRequest
0526:                        .getParameterValues("graph_ids");
0527:                if (graphsArray == null) {
0528:                    graphsArray = new String[0];
0529:                }
0530:                try {
0531:                    PreparedStatement pStmt = con
0532:                            .prepareStatement("UPDATE views SET name='"
0533:                                    + name
0534:                                    + "', description='"
0535:                                    + description
0536:                                    + "', graph_count="
0537:                                    + graphsArray.length
0538:                                    + ", modified=CURRENT_TIMESTAMP WHERE view_id="
0539:                                    + view_id);
0540:                    pStmt.executeUpdate();
0541:                    pStmt = con
0542:                            .prepareStatement("DELETE FROM views_graphs WHERE view_id="
0543:                                    + view_id);
0544:                    pStmt.executeUpdate();
0545:                    if (graphsArray != null)
0546:                        for (int i = 0; i < graphsArray.length; i++) {
0547:                            pStmt = con
0548:                                    .prepareStatement("INSERT INTO views_graphs VALUES("
0549:                                            + view_id
0550:                                            + ","
0551:                                            + graphsArray[i]
0552:                                            + ")");
0553:                            pStmt.executeUpdate();
0554:                        }
0555:                    con.close();
0556:                    actionResponse.setRenderParameter("message",
0557:                            "<font color=\"green\"><strong><li>View " + name
0558:                                    + " has been updated</li></strong></font>");
0559:                    return;
0560:
0561:                } catch (Exception e) {
0562:                    actionResponse.setRenderParameter("message",
0563:                            "<font color=\"red\"><strong><li>Error updating View "
0564:                                    + name + "</li></strong></font>"
0565:                                    + e.getMessage());
0566:                    return;
0567:                }
0568:            }
0569:
0570:            private void addView(ActionRequest actionRequest,
0571:                    ActionResponse actionResponse) {
0572:                DBManager DBase = new DBManager();
0573:                Connection con = DBase.getConnection();
0574:                String name = actionRequest.getParameter("name");
0575:                String description = actionRequest.getParameter("description");
0576:                String[] graphsArray = actionRequest
0577:                        .getParameterValues("graph_ids");
0578:                if (graphsArray == null) {
0579:                    graphsArray = new String[0];
0580:                }
0581:                try {
0582:                    PreparedStatement pStmt = con
0583:                            .prepareStatement("INSERT INTO views (name, description, graph_count, modified, added) VALUES ('"
0584:                                    + name
0585:                                    + "','"
0586:                                    + description
0587:                                    + "',"
0588:                                    + graphsArray.length
0589:                                    + ",CURRENT_TIMESTAMP,CURRENT_TIMESTAMP)");
0590:                    pStmt.executeUpdate();
0591:                    pStmt = con
0592:                            .prepareStatement("select view_id from views ORDER BY view_id DESC");
0593:                    ResultSet rs = pStmt.executeQuery();
0594:                    if (rs.next()) {
0595:                        Integer view_id = rs.getInt("view_id");
0596:                        for (int i = 0; i < graphsArray.length; i++) {
0597:                            pStmt = con
0598:                                    .prepareStatement("INSERT INTO views_graphs VALUES("
0599:                                            + view_id
0600:                                            + ","
0601:                                            + graphsArray[i]
0602:                                            + ")");
0603:                            pStmt.executeUpdate();
0604:                        }
0605:                    }
0606:                    con.close();
0607:                    actionResponse.setRenderParameter("message",
0608:                            "<font color=\"green\"><strong><li>View " + name
0609:                                    + " has been added</li></strong></font>");
0610:                } catch (Exception e) {
0611:                    actionResponse.setRenderParameter("message",
0612:                            "<font color=\"red\"><strong><li>Error adding View "
0613:                                    + name + "</li></strong></font>"
0614:                                    + e.getMessage());
0615:                } finally {
0616:                    try {
0617:                        con.close();
0618:                    } catch (Exception e) {
0619:
0620:                    }
0621:                }
0622:            }
0623:
0624:            private void updateServer(ActionRequest actionRequest,
0625:                    ActionResponse actionResponse) {
0626:                String server_id = actionRequest.getParameter("server_id");
0627:                actionResponse.setRenderParameter("server_id", server_id);
0628:                DBManager DBase = new DBManager();
0629:                Connection con = DBase.getConnection();
0630:                String name = actionRequest.getParameter("name");
0631:                String ip = actionRequest.getParameter("ip");
0632:                String password = actionRequest.getParameter("password");
0633:                String username = actionRequest.getParameter("username");
0634:                String snapshot = actionRequest.getParameter("snapshot");
0635:                String retention = actionRequest.getParameter("retention");
0636:                Integer port = Integer.parseInt(actionRequest
0637:                        .getParameter("port"));
0638:                Integer protocol = Integer.parseInt(actionRequest
0639:                        .getParameter("protocol"));
0640:                // encrypt the password
0641:                if (password != null && !password.equals("")) {
0642:                    password = EncryptionManager.encrypt(password);
0643:                }
0644:
0645:                try {
0646:                    // update the client side db (table = SERVERS)
0647:                    if (password.equals("") || password == null) {
0648:                        PreparedStatement pStmt = con
0649:                                .prepareStatement("UPDATE servers SET name='"
0650:                                        + name
0651:                                        + "', ip='"
0652:                                        + ip
0653:                                        + "', username='"
0654:                                        + username
0655:                                        + "', modified=CURRENT_TIMESTAMP, last_seen=CURRENT_TIMESTAMP, "
0656:                                        + "port=" + port + ",protocol="
0657:                                        + protocol + " WHERE server_id="
0658:                                        + server_id);
0659:                        pStmt.executeUpdate();
0660:                        // when user did not specify the password, just grab it from the
0661:                        // db
0662:                        pStmt = con
0663:                                .prepareStatement("SELECT password FROM servers WHERE server_id="
0664:                                        + server_id);
0665:                        ResultSet s = pStmt.executeQuery();
0666:                        if (s.next()) {
0667:                            password = s.getString("password");
0668:                        } else {
0669:                            actionResponse
0670:                                    .setRenderParameter(
0671:                                            "message",
0672:                                            "<font color=\"red\"><strong><li>Error updating server</li></strong></font>"
0673:                                                    + "Password was not found in the database for server_id="
0674:                                                    + server_id);
0675:                            con.close();
0676:                            return;
0677:                        }
0678:                    } else {
0679:                        PreparedStatement pStmt = con
0680:                                .prepareStatement("UPDATE servers SET name='"
0681:                                        + name
0682:                                        + "', ip='"
0683:                                        + ip
0684:                                        + "', username='"
0685:                                        + username
0686:                                        + "', password='"
0687:                                        + password
0688:                                        + "', modified=CURRENT_TIMESTAMP, last_seen=CURRENT_TIMESTAMP, "
0689:                                        + "port=" + port + ",protocol="
0690:                                        + protocol + " WHERE server_id="
0691:                                        + server_id);
0692:                        pStmt.executeUpdate();
0693:                    }
0694:                    con.close();
0695:                    // update the server side db
0696:                    if (snapshot == null || retention == null) {
0697:                        // do not update if we do not know
0698:                    } else {
0699:                        (new MRCConnector(ip, username, password, port,
0700:                                protocol)).setSnapshotDuration(Long
0701:                                .parseLong(snapshot) * 1000 * 60);
0702:                        (new MRCConnector(ip, username, password, port,
0703:                                protocol)).setSnapshotRetention(Integer
0704:                                .parseInt(retention));
0705:                    }
0706:                    // set success message
0707:                    actionResponse
0708:                            .setRenderParameter(
0709:                                    "message",
0710:                                    "<font color=\"green\"><strong><li>Server has been updated</li></strong></font>");
0711:                } catch (Exception e) {
0712:                    actionResponse.setRenderParameter("message",
0713:                            "<font color=\"red\"><strong><li>Error updating server</li></strong></font>"
0714:                                    + e.getMessage());
0715:                }
0716:            }
0717:
0718:            private void addServer(ActionRequest actionRequest,
0719:                    ActionResponse actionResponse) {
0720:                DBManager DBase = new DBManager();
0721:                Connection con = DBase.getConnection();
0722:                String name = actionRequest.getParameter("name");
0723:                String ip = actionRequest.getParameter("ip");
0724:                int protocol = Integer.parseInt(actionRequest
0725:                        .getParameter("protocol"));
0726:                int port = Integer.parseInt(actionRequest.getParameter("port"));
0727:                String password = actionRequest.getParameter("password");
0728:                String username = actionRequest.getParameter("username");
0729:                // encrypt the password
0730:                if (password != null && !password.equals("")) {
0731:                    password = EncryptionManager.encrypt(password);
0732:                }
0733:                try {
0734:                    PreparedStatement pStmt = con
0735:                            .prepareStatement("INSERT INTO servers (name, ip, username, password, modified, last_seen, added, port, protocol) VALUES ('"
0736:                                    + name
0737:                                    + "','"
0738:                                    + ip
0739:                                    + "','"
0740:                                    + username
0741:                                    + "','"
0742:                                    + password
0743:                                    + "',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,"
0744:                                    + port + "," + protocol + ")");
0745:                    pStmt.executeUpdate();
0746:                    actionResponse.setRenderParameter("message",
0747:                            "<font color=\"green\"><strong><li>Server " + name
0748:                                    + " at " + ip
0749:                                    + " has been added.</li></strong></font>");
0750:
0751:                } catch (Exception e) {
0752:                    actionResponse.setRenderParameter("message",
0753:                            "<font color=\"red\"><strong><li>Error adding server</li></strong></font>"
0754:                                    + e.getMessage());
0755:                } finally {
0756:                    try {
0757:                        con.close();
0758:                    } catch (Exception e) {
0759:
0760:                    }
0761:                }
0762:            }
0763:
0764:            private void deleteServer(ActionRequest actionRequest,
0765:                    ActionResponse actionResponse) {
0766:                String server_id = actionRequest.getParameter("server_id");
0767:                actionResponse.setRenderParameter("server_id", server_id);
0768:                DBManager DBase = new DBManager();
0769:                Connection con = DBase.getConnection();
0770:
0771:                try {
0772:                    PreparedStatement pStmt = con
0773:                            .prepareStatement("DELETE FROM graphs WHERE server_id="
0774:                                    + server_id);
0775:                    pStmt.executeUpdate();
0776:
0777:                    pStmt = con
0778:                            .prepareStatement("DELETE FROM servers WHERE server_id="
0779:                                    + server_id);
0780:                    pStmt.executeUpdate();
0781:                    con.close();
0782:                    actionResponse
0783:                            .setRenderParameter(
0784:                                    "message",
0785:                                    "<font color=\"green\"><strong><li>Server and associated graphs have been deleted</li></strong></font>");
0786:                    return;
0787:
0788:                } catch (Exception e) {
0789:                    actionResponse.setRenderParameter("message",
0790:                            "<font color=\"red\"><strong><li>Error deleting server</li></strong></font>"
0791:                                    + e.getMessage());
0792:                    return;
0793:                }
0794:            }
0795:
0796:            private void deleteView(ActionRequest actionRequest,
0797:                    ActionResponse actionResponse) {
0798:                String view_id = actionRequest.getParameter("view_id");
0799:                actionResponse.setRenderParameter("view_id", view_id);
0800:                DBManager DBase = new DBManager();
0801:                Connection con = DBase.getConnection();
0802:
0803:                try {
0804:                    PreparedStatement pStmt = con
0805:                            .prepareStatement("DELETE FROM views WHERE view_id="
0806:                                    + view_id);
0807:                    pStmt.executeUpdate();
0808:                    pStmt = con
0809:                            .prepareStatement("DELETE FROM views_graphs WHERE view_id="
0810:                                    + view_id);
0811:                    pStmt.executeUpdate();
0812:                    con.close();
0813:                    actionResponse
0814:                            .setRenderParameter("message",
0815:                                    "<font color=\"green\"><strong><li>View has been deleted</li></strong></font>");
0816:                    return;
0817:
0818:                } catch (Exception e) {
0819:                    actionResponse.setRenderParameter("message",
0820:                            "<font color=\"red\"><strong><li>Error deleting view</li></strong></font>"
0821:                                    + e.getMessage());
0822:                    return;
0823:                }
0824:            }
0825:
0826:            private void addGraph(ActionRequest actionRequest,
0827:                    ActionResponse actionResponse) {
0828:                DBManager DBase = new DBManager();
0829:                Connection con = DBase.getConnection();
0830:                String name = actionRequest.getParameter("name");
0831:                String description = actionRequest.getParameter("description");
0832:                String server_id = actionRequest.getParameter("server_id");
0833:                String xlabel = actionRequest.getParameter("xlabel");
0834:                String ylabel = actionRequest.getParameter("ylabel");
0835:                String timeframe = actionRequest.getParameter("timeframe");
0836:                String mbean = actionRequest.getParameter("mbean");
0837:                String dataname1 = actionRequest.getParameter("dataname1");
0838:                String data1operation = actionRequest
0839:                        .getParameter("data1operation");
0840:                String operation = actionRequest.getParameter("operation");
0841:                int showArchive = 0;
0842:                if (actionRequest.getParameter("showArchive") != null
0843:                        && actionRequest.getParameter("showArchive").equals(
0844:                                "on")) {
0845:                    showArchive = 1;
0846:                }
0847:
0848:                if (operation.equals("other")) {
0849:                    operation = actionRequest.getParameter("othermath");
0850:                }
0851:                String dataname2 = actionRequest.getParameter("dataname2");
0852:                String data2operation = actionRequest
0853:                        .getParameter("data2operation");
0854:                if (data2operation == null)
0855:                    data2operation = "A";
0856:                try {
0857:                    PreparedStatement pStmt = con
0858:                            .prepareStatement("INSERT INTO graphs (server_id, name, description, timeframe, mbean, dataname1, xlabel, ylabel, data1operation, operation, data2operation, dataname2, warninglevel1, warninglevel2, added, modified, last_seen, archive) VALUES ("
0859:                                    + server_id
0860:                                    + ",'"
0861:                                    + name
0862:                                    + "','"
0863:                                    + description
0864:                                    + "',"
0865:                                    + timeframe
0866:                                    + ",'"
0867:                                    + mbean
0868:                                    + "','"
0869:                                    + dataname1
0870:                                    + "','"
0871:                                    + xlabel
0872:                                    + "','"
0873:                                    + ylabel
0874:                                    + "','"
0875:                                    + data1operation
0876:                                    + "','"
0877:                                    + operation
0878:                                    + "','"
0879:                                    + data2operation
0880:                                    + "','"
0881:                                    + dataname2
0882:                                    + "',0,0,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,"
0883:                                    + showArchive + ")");
0884:                    pStmt.executeUpdate();
0885:                    con.close();
0886:                    actionResponse.setRenderParameter("message",
0887:                            "<font color=\"green\"><strong><li>Graph " + name
0888:                                    + " has been added.</li></strong></font>");
0889:                    return;
0890:
0891:                } catch (Exception e) {
0892:                    actionResponse.setRenderParameter("message",
0893:                            "<font color=\"red\"><strong><li>Error adding graph</li></strong></font>"
0894:                                    + e.getMessage());
0895:                    return;
0896:                }
0897:            }
0898:
0899:            private void updateGraph(ActionRequest actionRequest,
0900:                    ActionResponse actionResponse) {
0901:                DBManager DBase = new DBManager();
0902:                Connection con = DBase.getConnection();
0903:                String graph_id = actionRequest.getParameter("graph_id");
0904:                actionResponse.setRenderParameter("graph_id", graph_id);
0905:
0906:                String name = actionRequest.getParameter("name");
0907:                String description = actionRequest.getParameter("description");
0908:                String server_id = actionRequest.getParameter("server_id");
0909:                String xlabel = actionRequest.getParameter("xlabel");
0910:                String ylabel = actionRequest.getParameter("ylabel");
0911:                String timeframe = actionRequest.getParameter("timeframe");
0912:                String mbean = actionRequest.getParameter("mbean");
0913:                String dataname1 = actionRequest.getParameter("dataname1");
0914:                String data1operation = actionRequest
0915:                        .getParameter("data1operation");
0916:                String operation = actionRequest.getParameter("operation");
0917:                int archive = 0;
0918:                if (actionRequest.getParameter("showArchive") != null
0919:                        && actionRequest.getParameter("showArchive").equals(
0920:                                "on")) {
0921:                    archive = 1;
0922:                }
0923:
0924:                if (operation.equals("other")) {
0925:                    operation = actionRequest.getParameter("othermath");
0926:                }
0927:                String dataname2 = actionRequest.getParameter("dataname2");
0928:                String data2operation = actionRequest
0929:                        .getParameter("data2operation");
0930:                if (data2operation == null)
0931:                    data2operation = "A";
0932:                try {
0933:                    PreparedStatement pStmt = con
0934:                            .prepareStatement("UPDATE graphs SET server_id="
0935:                                    + server_id
0936:                                    + ", name='"
0937:                                    + name
0938:                                    + "', description='"
0939:                                    + description
0940:                                    + "', timeframe="
0941:                                    + timeframe
0942:                                    + ", mbean='"
0943:                                    + mbean
0944:                                    + "', dataname1='"
0945:                                    + dataname1
0946:                                    + "', xlabel='"
0947:                                    + xlabel
0948:                                    + "', ylabel='"
0949:                                    + ylabel
0950:                                    + "', data1operation='"
0951:                                    + data1operation
0952:                                    + "', operation='"
0953:                                    + operation
0954:                                    + "', data2operation='"
0955:                                    + data2operation
0956:                                    + "', dataname2='"
0957:                                    + dataname2
0958:                                    + "', warninglevel1=0, warninglevel2=0, modified=CURRENT_TIMESTAMP, archive="
0959:                                    + archive + " WHERE graph_id=" + graph_id);
0960:                    pStmt.executeUpdate();
0961:                    con.close();
0962:                    actionResponse
0963:                            .setRenderParameter(
0964:                                    "message",
0965:                                    "<font color=\"green\"><strong><li>Graph "
0966:                                            + name
0967:                                            + " has been updated.</li></strong></font>");
0968:                    return;
0969:
0970:                } catch (Exception e) {
0971:                    actionResponse.setRenderParameter("message",
0972:                            "<font color=\"red\"><strong><li>Error editing graph</li></strong></font>"
0973:                                    + e.getMessage());
0974:                    return;
0975:                }
0976:            }
0977:
0978:            private void deleteGraph(ActionRequest actionRequest,
0979:                    ActionResponse actionResponse) {
0980:                String graph_id = actionRequest.getParameter("graph_id");
0981:                actionResponse.setRenderParameter("graph_id", graph_id);
0982:                DBManager DBase = new DBManager();
0983:                Connection con = DBase.getConnection();
0984:
0985:                try {
0986:                    // remove the graph
0987:                    PreparedStatement pStmt = con
0988:                            .prepareStatement("DELETE FROM graphs WHERE graph_id="
0989:                                    + graph_id);
0990:                    pStmt.executeUpdate();
0991:                    // fetch all views associated with this graph
0992:                    pStmt = con
0993:                            .prepareStatement("SELECT view_id FROM views_graphs WHERE graph_id="
0994:                                    + graph_id);
0995:                    ResultSet view_ids = pStmt.executeQuery();
0996:                    // reduce the graph_count from all views associated with the graph
0997:                    while (view_ids.next()) {
0998:                        pStmt = con
0999:                                .prepareStatement("UPDATE views SET graph_count=graph_count-1 WHERE view_id="
1000:                                        + view_ids.getString("view_id"));
1001:                        pStmt.executeUpdate();
1002:                    }
1003:                    // remove the relationship between graphs and views
1004:                    pStmt = con
1005:                            .prepareStatement("DELETE FROM views_graphs WHERE graph_id="
1006:                                    + graph_id);
1007:                    pStmt.executeUpdate();
1008:                    con.close();
1009:                    actionResponse
1010:                            .setRenderParameter("message",
1011:                                    "<font color=\"green\"><strong><li>Graph has been deleted</li></strong></font>");
1012:                    return;
1013:
1014:                } catch (Exception e) {
1015:                    actionResponse.setRenderParameter("message",
1016:                            "<font color=\"red\"><strong><li>Error deleting graph</li></strong></font>"
1017:                                    + e.getMessage());
1018:                    return;
1019:                }
1020:            }
1021:
1022:            private String startTrackingMbean(String server_id, String mbean) {
1023:                PreparedStatement pStmt = null;
1024:                ResultSet rs = null;
1025:                MRCConnector mrc = null;
1026:                DBManager DBase = new DBManager();
1027:                Connection con = DBase.getConnection();
1028:                String server_ip = null;
1029:                String username = null;
1030:                String password = null;
1031:                int protocol = 0;
1032:                int port = -1;
1033:                // fetch server information
1034:                try {
1035:                    pStmt = con
1036:                            .prepareStatement("SELECT * FROM servers WHERE server_id="
1037:                                    + server_id);
1038:                    rs = pStmt.executeQuery();
1039:                    if (!rs.next()) {
1040:                        return "<font color=\"red\"><strong><li>DATABASE ERROR: Server id "
1041:                                + server_id
1042:                                + " not found in database</li></strong></font>";
1043:                    }
1044:                    server_ip = rs.getString("ip");
1045:                    password = rs.getString("password");
1046:                    username = rs.getString("username");
1047:                    port = rs.getInt("port");
1048:                    protocol = rs.getInt("protocol");
1049:                } catch (SQLException e) {
1050:                    return "<font color=\"red\"><strong><li>DATABASE ERROR: "
1051:                            + e.getMessage() + "</li></strong></font>";
1052:                }
1053:                // attempt to connect to the mrc server
1054:                try {
1055:                    con.close();
1056:                    mrc = new MRCConnector(server_ip, username, password, port,
1057:                            protocol);
1058:                } catch (Exception e) {
1059:                    return "<font color=\"red\"><strong><li>MRC ERROR: Unable to connect to server "
1060:                            + server_ip
1061:                            + ": "
1062:                            + e.getMessage()
1063:                            + "</li></strong></font>";
1064:                }
1065:
1066:                // tell the mrc server to start tracking an mbean
1067:                try {
1068:                    if (mrc.startTrackingMbean(mbean)) {
1069:                        String mbarr[] = mbean.split("name=");
1070:                        return "<font color=\"green\"><strong><li>MBean "
1071:                                + mbarr[1] + " tracking on server "
1072:                                + rs.getString("name")
1073:                                + "</li></strong></font>";
1074:                    } else {
1075:                        String mbarr[] = mbean.split("name=");
1076:                        return "<font color=\"red\"><strong><li>ERROR: MBean "
1077:                                + mbarr[1]
1078:                                + " could <b>NOT</b> be tracked on server "
1079:                                + rs.getString("name")
1080:                                + "</li></strong></font>";
1081:                    }
1082:                } catch (Exception e) {
1083:                    return "<font color=\"red\"><strong><li>MRC ERROR: MBean "
1084:                            + mbean + " could <b>NOT</b> be tracked on server "
1085:                            + server_ip + ": " + e.getMessage()
1086:                            + "</li></strong></font>";
1087:                }
1088:            }
1089:
1090:            private String stopTrackingMbean(String server_id, String mbean) {
1091:                PreparedStatement pStmt = null;
1092:                ResultSet rs = null;
1093:                MRCConnector mrc = null;
1094:                DBManager DBase = new DBManager();
1095:                Connection con = DBase.getConnection();
1096:                String server_ip = null;
1097:                String username = null;
1098:                String password = null;
1099:                int port = -1;
1100:                int protocol = 0;
1101:                // fetch server's information
1102:                try {
1103:                    pStmt = con
1104:                            .prepareStatement("SELECT * FROM servers WHERE server_id="
1105:                                    + server_id);
1106:                    rs = pStmt.executeQuery();
1107:                    if (!rs.next()) {
1108:                        return "<font color=\"red\"><strong><li>DATABASE ERROR: Server id "
1109:                                + server_id
1110:                                + " not found in database</li></strong></font>";
1111:                    }
1112:                    server_ip = rs.getString("ip");
1113:                    password = rs.getString("password");
1114:                    username = rs.getString("username");
1115:                    port = rs.getInt("port");
1116:                    protocol = rs.getInt("protocol");
1117:                } catch (SQLException e) {
1118:                    return "<font color=\"red\"><strong><li>DATABASE ERROR: "
1119:                            + e.getMessage() + "</li></strong></font>";
1120:                }
1121:                // attempt to connect to the mrc-server
1122:                try {
1123:                    con.close();
1124:                    mrc = new MRCConnector(server_ip, username, password, port,
1125:                            protocol);
1126:                } catch (Exception e) {
1127:                    return "<font color=\"red\"><strong><li>MRC ERROR: Unable to connect to server "
1128:                            + server_ip
1129:                            + ": "
1130:                            + e.getMessage()
1131:                            + "</li></strong></font>";
1132:                }
1133:                // tell the mrc-server to stop tracking some mbean
1134:                try {
1135:                    if (mrc.stopTrackingMbean(mbean)) {
1136:                        String mbarr[] = mbean.split("name=");
1137:                        return "<font color=\"green\"><strong><li>MBean "
1138:                                + mbarr[1]
1139:                                + " removed from tracking on server "
1140:                                + rs.getString("name")
1141:                                + "</li></strong></font>";
1142:                    } else {
1143:                        String mbarr[] = mbean.split("name=");
1144:                        return "<font color=\"red\"><strong><li>ERROR: MBean "
1145:                                + mbarr[1]
1146:                                + " could <b>NOT</b> be removed from tracking on server "
1147:                                + rs.getString("name")
1148:                                + "</li></strong></font>";
1149:                    }
1150:                } catch (Exception e) {
1151:                    return "<font color=\"red\"><strong><li>MRC ERROR: MBean "
1152:                            + mbean
1153:                            + " could <b>NOT</b> be removed from tracking on server "
1154:                            + server_ip + ": " + e.getMessage()
1155:                            + "</li></strong></font>";
1156:                }
1157:            }
1158:
1159:            private String stopThread(String server_id) {
1160:                PreparedStatement pStmt = null;
1161:                ResultSet rs = null;
1162:                MRCConnector mrc = null;
1163:                DBManager DBase = new DBManager();
1164:                Connection con = DBase.getConnection();
1165:                String server_ip = null;
1166:                String username = null;
1167:                String password = null;
1168:                int port = -1;
1169:                int protocol = 0;
1170:                // fetch the server's information
1171:                try {
1172:                    pStmt = con
1173:                            .prepareStatement("SELECT * FROM servers WHERE server_id="
1174:                                    + server_id);
1175:                    rs = pStmt.executeQuery();
1176:                    if (!rs.next()) {
1177:                        return "<font color=\"red\"><strong><li>DATABASE ERROR: Server id "
1178:                                + server_id
1179:                                + " not found in database</li></strong></font>";
1180:                    }
1181:                    server_ip = rs.getString("ip");
1182:                    password = rs.getString("password");
1183:                    username = rs.getString("username");
1184:                    port = rs.getInt("port");
1185:                    protocol = rs.getInt("protocol");
1186:                } catch (SQLException e) {
1187:                    return "<font color=\"red\"><strong><li>DATABASE ERROR: "
1188:                            + e.getMessage() + "</li></strong></font>";
1189:                }
1190:                // attempt to connect to the mrc-server
1191:                try {
1192:                    con.close();
1193:                    mrc = new MRCConnector(server_ip, username, password, port,
1194:                            protocol);
1195:                } catch (Exception e) {
1196:                    return "<font color=\"red\"><strong><li>MRC ERROR: Unable to connect to server "
1197:                            + server_ip
1198:                            + ": "
1199:                            + e.getMessage()
1200:                            + "</li></strong></font>";
1201:                }
1202:                // tell the mrc-server to stop taking snapshots
1203:                try {
1204:                    if (mrc.stopSnapshotThread()) {
1205:                        return "<font color=\"green\"><strong><li>Snapshot thread stopped on server "
1206:                                + rs.getString("name")
1207:                                + "</li></strong></font>";
1208:                    } else {
1209:                        return "<font color=\"red\"><strong><li>ERROR: Snapshot thread could <b>NOT</b> be stopped on server "
1210:                                + rs.getString("name")
1211:                                + "</li></strong></font>";
1212:                    }
1213:
1214:                } catch (Exception e) {
1215:                    return "<font color=\"red\"><strong><li>MRC ERROR: Snapshot thread could <b>NOT</b> be stopped on server "
1216:                            + server_ip
1217:                            + ": "
1218:                            + e.getMessage()
1219:                            + "</li></strong></font>";
1220:                }
1221:            }
1222:
1223:            private String startThread(String server_id, Long snapshotDuration) {
1224:                PreparedStatement pStmt = null;
1225:                ResultSet rs = null;
1226:                MRCConnector mrc = null;
1227:                DBManager DBase = new DBManager();
1228:                Connection con = DBase.getConnection();
1229:                String server_ip = null;
1230:                String username = null;
1231:                String password = null;
1232:                int port = -1;
1233:                int protocol = 0;
1234:                // fetch the server's information
1235:                try {
1236:                    pStmt = con
1237:                            .prepareStatement("SELECT * FROM servers WHERE server_id="
1238:                                    + server_id);
1239:                    rs = pStmt.executeQuery();
1240:                    if (!rs.next()) {
1241:                        return "<font color=\"red\"><strong><li>DATABASE ERROR: Server id "
1242:                                + server_id
1243:                                + " not found in database</li></strong></font>";
1244:                    }
1245:                    server_ip = rs.getString("ip");
1246:                    password = rs.getString("password");
1247:                    username = rs.getString("username");
1248:                    port = rs.getInt("port");
1249:                    protocol = rs.getInt("protocol");
1250:                } catch (SQLException e) {
1251:                    return "<font color=\"red\"><strong><li>DATABASE ERROR: "
1252:                            + e.getMessage() + "</li></strong></font>";
1253:                }
1254:                // attempt to connect to the mrc-server
1255:                try {
1256:                    con.close();
1257:                    mrc = new MRCConnector(server_ip, username, password, port,
1258:                            protocol);
1259:                } catch (Exception e) {
1260:                    return "<font color=\"red\"><strong><li>MRC ERROR: Unable to connect to server "
1261:                            + server_ip
1262:                            + ": "
1263:                            + e.getMessage()
1264:                            + "</li></strong></font>";
1265:                }
1266:                // tell the mrc-server to start the collection of statistics
1267:                try {
1268:                    if (mrc.startSnapshotThread(new Long(snapshotDuration))) {
1269:                        return "<font color=\"green\"><strong><li>Snapshot thread started on server "
1270:                                + rs.getString("name")
1271:                                + "</li></strong></font>";
1272:                    } else {
1273:                        return "<font color=\"red\"><strong><li>ERROR: Snapshot thread could <b>NOT</b> be started on server "
1274:                                + rs.getString("name")
1275:                                + "</li></strong></font>";
1276:                    }
1277:                } catch (Exception e) {
1278:                    return "<font color=\"red\"><strong><li>MRC ERROR: Snapshot thread could <b>NOT</b> be started on server "
1279:                            + server_ip
1280:                            + ": "
1281:                            + e.getMessage()
1282:                            + "</li></strong></font>";
1283:                }
1284:            }
1285:
1286:            @Override
1287:            public void init(PortletConfig portletConfig)
1288:                    throws PortletException {
1289:                super .init(portletConfig);
1290:                normalView = portletConfig.getPortletContext()
1291:                        .getRequestDispatcher(NORMALVIEW_JSP);
1292:                viewViews = portletConfig.getPortletContext()
1293:                        .getRequestDispatcher(VIEWVIEWS_JSP);
1294:                viewServers = portletConfig.getPortletContext()
1295:                        .getRequestDispatcher(VIEWSERVERS_JSP);
1296:                viewGraphs = portletConfig.getPortletContext()
1297:                        .getRequestDispatcher(VIEWGRAPHS_JSP);
1298:                pageView = portletConfig.getPortletContext()
1299:                        .getRequestDispatcher(PAGEVIEW_JSP);
1300:                editView = portletConfig.getPortletContext()
1301:                        .getRequestDispatcher(EDITVIEW_JSP);
1302:                addView = portletConfig.getPortletContext()
1303:                        .getRequestDispatcher(ADDVIEW_JSP);
1304:                addGraph = portletConfig.getPortletContext()
1305:                        .getRequestDispatcher(ADDGRAPH_JSP);
1306:                editGraph = portletConfig.getPortletContext()
1307:                        .getRequestDispatcher(EDITGRAPH_JSP);
1308:                viewServer = portletConfig.getPortletContext()
1309:                        .getRequestDispatcher(VIEWSERVER_JSP);
1310:                editServer = portletConfig.getPortletContext()
1311:                        .getRequestDispatcher(EDITSERVER_JSP);
1312:                addServer = portletConfig.getPortletContext()
1313:                        .getRequestDispatcher(ADDSERVER_JSP);
1314:                helpView = portletConfig.getPortletContext()
1315:                        .getRequestDispatcher(HELPVIEW_JSP);
1316:                editNormalView = portletConfig.getPortletContext()
1317:                        .getRequestDispatcher(EDITNORMALVIEW_JSP);
1318:            }
1319:
1320:            @Override
1321:            public void destroy() {
1322:                normalView = null;
1323:                viewViews = null;
1324:                viewServers = null;
1325:                viewGraphs = null;
1326:                pageView = null;
1327:                editView = null;
1328:                addView = null;
1329:                addGraph = null;
1330:                editGraph = null;
1331:                viewServer = null;
1332:                editServer = null;
1333:                addServer = null;
1334:                helpView = null;
1335:                editNormalView = null;
1336:                super.destroy();
1337:            }
1338:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.