Home » geronimo-2.2-source-release » org.apache.geronimo.monitoring.console » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.geronimo.monitoring.console;
   18   
   19   import java.io.IOException;
   20   import java.util.ArrayList;
   21   import java.util.List;
   22   
   23   import javax.annotation.Resource;
   24   import javax.naming.Context;
   25   import javax.naming.InitialContext;
   26   import javax.naming.NamingException;
   27   import javax.persistence.EntityManager;
   28   import javax.persistence.PersistenceContext;
   29   import javax.portlet.ActionRequest;
   30   import javax.portlet.ActionResponse;
   31   import javax.portlet.PortletConfig;
   32   import javax.portlet.PortletException;
   33   import javax.portlet.PortletRequest;
   34   import javax.portlet.PortletRequestDispatcher;
   35   import javax.portlet.RenderRequest;
   36   import javax.portlet.RenderResponse;
   37   import javax.transaction.UserTransaction;
   38   
   39   import org.apache.geronimo.console.BasePortlet;
   40   import org.apache.geronimo.console.util.PortletManager;
   41   import org.apache.geronimo.crypto.EncryptionManager;
   42   import org.apache.geronimo.management.geronimo.WebContainer;
   43   import org.apache.geronimo.monitoring.console.data.Graph;
   44   import org.apache.geronimo.monitoring.console.data.Node;
   45   import org.apache.geronimo.monitoring.console.data.View;
   46   import org.slf4j.Logger;
   47   import org.slf4j.LoggerFactory;
   48   
   49   /**
   50    * STATS
   51    */
   52   public class MonitoringPortlet extends BasePortlet {
   53       Logger log = LoggerFactory.getLogger(MonitoringPortlet.class);
   54   
   55       private static final String NORMALVIEW_JSP = "/WEB-INF/view/monitoringNormal.jsp";
   56   
   57       private static final String VIEWVIEWS_JSP = "/WEB-INF/view/monitoringViews.jsp";
   58   
   59       private static final String VIEWSERVERS_JSP = "/WEB-INF/view/monitoringServers.jsp";
   60   
   61       private static final String VIEWGRAPHS_JSP = "/WEB-INF/view/monitoringGraphs.jsp";
   62   
   63       private static final String PAGEVIEW_JSP = "/WEB-INF/view/monitoringPage.jsp";
   64   
   65       private static final String EDITVIEW_JSP = "/WEB-INF/view/monitoringEditView.jsp";
   66   
   67       private static final String ADDVIEW_JSP = "/WEB-INF/view/monitoringAddView.jsp";
   68   
   69       private static final String ADDGRAPH_JSP = "/WEB-INF/view/monitoringAddGraph.jsp";
   70   
   71       private static final String EDITGRAPH_JSP = "/WEB-INF/view/monitoringEditGraph.jsp";
   72   
   73       private static final String VIEWSERVER_JSP = "/WEB-INF/view/monitoringViewServer.jsp";
   74   
   75       private static final String EDITSERVER_JSP = "/WEB-INF/view/monitoringEditServer.jsp";
   76   
   77       private static final String ADDSERVER_JSP = "/WEB-INF/view/monitoringAddServer.jsp";
   78   
   79       private static final String HELPVIEW_JSP = "/WEB-INF/view/monitoringHelp.jsp";
   80   
   81       private static final String EDITNORMALVIEW_JSP = "/WEB-INF/view/monitoringEdit.jsp";
   82   
   83       private PortletRequestDispatcher normalView;
   84   
   85       private PortletRequestDispatcher viewViews;
   86   
   87       private PortletRequestDispatcher viewServers;
   88   
   89       private PortletRequestDispatcher viewGraphs;
   90   
   91       private PortletRequestDispatcher pageView;
   92   
   93       private PortletRequestDispatcher editView;
   94   
   95       private PortletRequestDispatcher addView;
   96   
   97       private PortletRequestDispatcher addGraph;
   98   
   99       private PortletRequestDispatcher editGraph;
  100   
  101       private PortletRequestDispatcher viewServer;
  102   
  103       private PortletRequestDispatcher editServer;
  104   
  105       private PortletRequestDispatcher addServer;
  106   
  107       private PortletRequestDispatcher helpView;
  108   
  109       private PortletRequestDispatcher editNormalView;
  110       
  111       private String server;        
  112   
  113       //annotations don't work in portlets yet, see init method for initialization
  114       @Resource
  115       UserTransaction userTransaction;
  116   
  117       @PersistenceContext
  118       EntityManager entityManager;
  119   
  120       @Override
  121       public void processAction(ActionRequest actionRequest,
  122                                 ActionResponse actionResponse) throws PortletException, IOException {
  123           String action = actionRequest.getParameter("action");
  124           actionResponse.setRenderParameter("action", action);
  125           if (action.equals("showView")) {
  126               String view_id = actionRequest.getParameter("view_id");
  127               actionResponse.setRenderParameter("view_id", view_id);
  128           } else if (action.equals("showAllViews")) {
  129               // no parameters needed to be redirected to doView()
  130           } else if (action.equals("showAllServers")) {
  131               // no parameters needed to be redirected to doView()
  132           } else if (action.equals("showAllGraphs")) {
  133               // no parameters needed to be redirected to doView()
  134           } else if (action.equals("showEditView")) {
  135               String view_id = actionRequest.getParameter("view_id");
  136               actionResponse.setRenderParameter("view_id", view_id);
  137           } else if (action.equals("saveEditView")) {
  138               updateView(actionRequest, actionResponse);
  139           } else if (action.equals("showAddView")) {
  140               // no parameters needed to be redirected to doView()
  141           } else if (action.equals("saveAddView")) {
  142               addView(actionRequest, actionResponse);
  143           } else if (action.equals("showAddGraph")) {
  144               String server_id = actionRequest.getParameter("server_id");
  145               if (server_id != null)
  146                   actionResponse.setRenderParameter("server_id", server_id);
  147   
  148               String mbean = actionRequest.getParameter("mbean");
  149               if (mbean != null)
  150                   actionResponse.setRenderParameter("mbean", mbean);
  151   
  152               String dataname = actionRequest.getParameter("dataname");
  153               if (dataname != null)
  154                   actionResponse.setRenderParameter("dataname", dataname);
  155           } else if (action.equals("saveAddGraph")) {
  156               addGraph(actionRequest, actionResponse);
  157           } else if (action.equals("showEditGraph")) {
  158               String graph_id = actionRequest.getParameter("graph_id");
  159               actionResponse.setRenderParameter("graph_id", graph_id);
  160           } else if (action.equals("saveEditGraph")) {
  161               updateGraph(actionRequest, actionResponse);
  162           } else if (action.equals("deleteGraph")) {
  163               deleteGraph(actionRequest, actionResponse);
  164           } else if (action.equals("deleteView")) {
  165               deleteView(actionRequest, actionResponse);
  166           } else if (action.equals("showServer")) {
  167               String server_id = actionRequest.getParameter("server_id");
  168               actionResponse.setRenderParameter("server_id", server_id);
  169           } else if (action.equals("showEditServer")) {
  170               String server_id = actionRequest.getParameter("server_id");
  171               actionResponse.setRenderParameter("server_id", server_id);
  172           } else if (action.equals("saveEditServer")) {
  173               updateServer(actionRequest, actionResponse);
  174           } else if (action.equals("showAddServer")) {
  175               // no parameters needed to be redirected to doView()
  176           } else if (action.equals("deleteServer")) {
  177               deleteServer(actionRequest, actionResponse);
  178           } else if (action.equals("saveAddServer")) {
  179               addServer(actionRequest, actionResponse);
  180           } else if (action.equals("startTrackingMbean")) {
  181               String server_id = actionRequest.getParameter("server_id");
  182               actionResponse.setRenderParameter("server_id", server_id);
  183               String mbean = actionRequest.getParameter("mbean");
  184               actionResponse.setRenderParameter("mbean", mbean);
  185           } else if (action.equals("stopTrackingMbean")) {
  186               String server_id = actionRequest.getParameter("server_id");
  187               actionResponse.setRenderParameter("server_id", server_id);
  188               String mbean = actionRequest.getParameter("mbean");
  189               actionResponse.setRenderParameter("mbean", mbean);
  190           } else if (action.equals("stopThread")
  191                   || action.equals("disableServerViewQuery")) {
  192               String server_id = actionRequest.getParameter("server_id");
  193               stopThread(server_id, actionRequest);
  194               actionResponse.setRenderParameter("server_id", server_id);
  195           } else if (action.equals("startThread")
  196                   || action.equals("enableServerViewQuery")) {
  197               String server_id = actionRequest.getParameter("server_id");
  198               String snapshotDuration = actionRequest.getParameter("snapshotDuration");
  199               startThread(server_id, new Long(snapshotDuration), actionRequest);
  200               actionResponse.setRenderParameter("server_id", server_id);
  201               actionResponse.setRenderParameter("snapshotDuration", snapshotDuration);
  202           } else if (action.equals("disableServer")
  203                   || action.equals("disableEditServer")) {
  204               String server_id = actionRequest.getParameter("server_id");
  205               actionResponse.setRenderParameter("server_id", server_id);
  206               alterServerState(server_id, false, actionRequest);
  207           } else if (action.equals("enableServer")
  208                   || action.equals("enableEditServer")) {
  209               String server_id = actionRequest.getParameter("server_id");
  210               alterServerState(server_id, true, actionRequest);
  211               actionResponse.setRenderParameter("server_id", server_id);
  212           } else if (action.equals("testAddServerConnection")) {
  213               String name = actionRequest.getParameter("name");
  214               String ip = actionRequest.getParameter("ip");
  215               String username = actionRequest.getParameter("username");
  216               String password = actionRequest.getParameter("password");
  217               String password2 = actionRequest.getParameter("password2");
  218               Integer port = Integer.parseInt(actionRequest.getParameter("port"));
  219               String protocol = actionRequest.getParameter("protocol");
  220               testConnection(ip, username, password, port, protocol, actionRequest);
  221               actionResponse.setRenderParameter("name", name);
  222               actionResponse.setRenderParameter("username", username);
  223               actionResponse.setRenderParameter("ip", ip);
  224               //  Don't return the password in the output
  225   //            actionResponse.setRenderParameter("password", password);
  226   //            actionResponse.setRenderParameter("password2", password2);
  227               actionResponse.setRenderParameter("port", "" + port);
  228               actionResponse.setRenderParameter("protocol", protocol);
  229           } else if (action.equals("testEditServerConnection")) {
  230               String name = actionRequest.getParameter("name");
  231               String ip = actionRequest.getParameter("ip");
  232               String username = actionRequest.getParameter("username");
  233               String password = actionRequest.getParameter("password");
  234               String password2 = actionRequest.getParameter("password2");
  235               String server_id = actionRequest.getParameter("server_id");
  236               String snapshot = actionRequest.getParameter("snapshot");
  237               String retention = actionRequest.getParameter("retention");
  238               Integer port = Integer.parseInt(actionRequest.getParameter("port"));
  239               String protocol = actionRequest.getParameter("protocol");
  240               if (snapshot == null) {
  241                   snapshot = "";
  242               }
  243               if (retention == null) {
  244                   retention = "";
  245               }
  246               testConnection(ip, username, password, port, protocol, actionRequest);
  247               actionResponse.setRenderParameter("name", name);
  248               actionResponse.setRenderParameter("username", username);
  249               actionResponse.setRenderParameter("ip", ip);
  250               //  Don't return the password in the output
  251   //            actionResponse.setRenderParameter("password", password);
  252   //            actionResponse.setRenderParameter("password2", password2);
  253               actionResponse.setRenderParameter("snapshot", snapshot);
  254               actionResponse.setRenderParameter("server_id", server_id);
  255               actionResponse.setRenderParameter("retention", retention);
  256               actionResponse.setRenderParameter("port", "" + port);
  257               actionResponse.setRenderParameter("protocol", "" + protocol);
  258           }
  259           else if(action.equals("restoreData")){
  260               restoreData(actionRequest,actionResponse);
  261           }
  262       }
  263   
  264       private void testConnection(String ip, String username,
  265                                     String password, int port, String protocol, PortletRequest request) {
  266           MRCConnector mrc = null;
  267           try {
  268               mrc = new MRCConnector(ip, username, password, port, protocol);
  269               addInfoMessage(request, getLocalizedString(request, "mconsole.infoMsg01"));
  270           } catch (Exception e) {
  271               addInfoMessage(request, getLocalizedString(request, "mconsole.errorMsg01"), e.getMessage());
  272           } finally
  273           {
  274               if(null != mrc)
  275                   mrc.dispose();
  276           }
  277       }
  278   
  279       private void alterServerState(String server_id, boolean enable, PortletRequest request) {
  280           try {
  281               userTransaction.begin();
  282               try {
  283                   Node node = (Node) entityManager.createNamedQuery("nodeByName").setParameter("name", server_id).getSingleResult();
  284                   node.setEnabled(enable);
  285               } finally {
  286                   userTransaction.commit();
  287               }
  288               if (enable) {
  289                   addInfoMessage(request, getLocalizedString(request, "mconsole.infoMsg02", server_id));
  290               }
  291               else {
  292                   addInfoMessage(request, getLocalizedString(request, "mconsole.infoMsg03", server_id));
  293               }
  294           } catch (Exception e) {
  295               if (enable) {
  296                   addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg02", server_id), e.getMessage());
  297               }
  298               else {
  299               	addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg03", server_id), e.getMessage());
  300               }
  301           }
  302       }
  303   
  304       @Override
  305       public void doView(RenderRequest request, RenderResponse response)
  306               throws PortletException, IOException {
  307           String action = request.getParameter("action");
  308           if (action == null)
  309               action = "showNormal";
  310           if (action.equals("showView")) {
  311               addViewAttribute(request, true);
  312               pageView.include(request, response);
  313           } else if (action.equals("showAllViews")) {
  314               addAllViewsAttribute(request);
  315               viewViews.include(request, response);
  316           } else if (action.equals("showAllServers")) {
  317               addAllNodesAttribute(request);
  318               viewServers.include(request, response);
  319           } else if (action.equals("showAllGraphs")) {
  320               addAllGraphsAttribute(request);
  321               viewGraphs.include(request, response);
  322           } else if (action.equals("showServer")) {
  323               String server_id = request.getParameter("server_id");
  324               request.setAttribute("server_id", server_id);
  325               addNodeAttribute(request);
  326               viewServer.include(request, response);
  327           } else if (action.equals("startTrackingMbean")) {
  328               String server_id = request.getParameter("server_id");
  329               request.setAttribute("server_id", server_id);
  330               String mbean = request.getParameter("mbean");
  331               request.setAttribute("mbean", mbean);
  332               startTrackingMbean(server_id, mbean, request);
  333               addNodeAttribute(request);
  334               viewServer.include(request, response);
  335           } else if (action.equals("stopTrackingMbean")) {
  336               String server_id = request.getParameter("server_id");
  337               request.setAttribute("server_id", server_id);
  338               String mbean = request.getParameter("mbean");
  339               request.setAttribute("mbean", mbean);
  340               stopTrackingMbean(server_id, mbean, request);
  341               addNodeAttribute(request);
  342               viewServer.include(request, response);
  343           } else if (action.equals("stopThread")) {
  344               normalView(request, response);
  345           } else if (action.equals("startThread")) {
  346               normalView(request, response);
  347           } else if (action.equals("disableServerViewQuery") || action.equals("enableServerViewQuery")) {
  348               String server_id = request.getParameter("server_id");
  349               request.setAttribute("server_id", server_id);
  350               addNodeAttribute(request);
  351               viewServer.include(request, response);
  352           } else {
  353               normalView(request, response);
  354           }
  355       }
  356   
  357       @Override
  358       protected void doHelp(RenderRequest renderRequest,
  359                             RenderResponse renderResponse) throws PortletException, IOException {
  360           helpView.include(renderRequest, renderResponse);
  361       }
  362   
  363       @Override
  364       protected void doEdit(RenderRequest request, RenderResponse response)
  365               throws PortletException, IOException {
  366           String action = request.getParameter("action");
  367           if (action == null)
  368               action = "showNormal";
  369           if(request.isUserInRole("admin")){
  370           if (action.equals("showEditView")) {
  371               String view_id = request.getParameter("view_id");
  372               request.setAttribute("view_id", view_id);
  373               addViewAttribute(request, false);
  374               addAllGraphsAttribute(request);
  375               editView.include(request, response);
  376           } else if (action.equals("saveEditView")) {
  377               String view_id = request.getParameter("view_id");
  378               request.setAttribute("view_id", view_id);
  379               addViewAttribute(request, false);
  380               addAllGraphsAttribute(request);
  381               editView.include(request, response);
  382           } else if (action.equals("showAddView")) {
  383               addAllGraphsAttribute(request);
  384               addView.include(request, response);
  385           } else if (action.equals("saveAddView")) {
  386               normalView(request, response);
  387           } else if (action.equals("showAddGraph")) {
  388               String server_id = request.getParameter("server_id");
  389               request.setAttribute("server_id", server_id);
  390               String mbean = request.getParameter("mbean");
  391               request.setAttribute("mbean", mbean);
  392               String dataname = request.getParameter("dataname");
  393               request.setAttribute("dataname", dataname);
  394               addAllNodesAttribute(request);
  395               addGraph.include(request, response);
  396           } else if (action.equals("saveAddGraph")) {
  397               normalView(request, response);
  398           } else if (action.equals("showEditGraph")) {
  399               String graph_id = request.getParameter("graph_id");
  400               request.setAttribute("graph_id", graph_id);
  401               addGraphAttribute(request);
  402               addAllNodesAttribute(request);
  403               editGraph.include(request, response);
  404           } else if (action.equals("saveEditGraph")) {
  405               String graph_id = request.getParameter("graph_id");
  406               request.setAttribute("graph_id", graph_id);
  407               addGraphAttribute(request);
  408               addAllNodesAttribute(request);
  409               editGraph.include(request, response);
  410           } else if (action.equals("deleteGraph")) {
  411               normalView(request, response);
  412           } else if (action.equals("deleteView")) {
  413               normalView(request, response);
  414           } else if (action.equals("showEditServer")) {
  415               String server_id = request.getParameter("server_id");
  416               request.setAttribute("server_id", server_id);
  417               addNodeAttribute(request);
  418               editServer.include(request, response);
  419           } else if (action.equals("saveEditServer")) {
  420               String server_id = request.getParameter("server_id");
  421               request.setAttribute("server_id", server_id);
  422               addNodeAttribute(request);
  423               editServer.include(request, response);
  424           } else if (action.equals("showAddServer")) {
  425               addServer.include(request, response);
  426           } else if (action.equals("saveAddServer")) {
  427               normalView(request, response);
  428           } else if (action.equals("deleteServer")) {
  429               normalView(request, response);
  430           } else if (action.equals("testAddServerConnection")) {
  431               request.setAttribute("name", request.getParameter("name"));
  432               request.setAttribute("ip", request.getParameter("ip"));
  433               request.setAttribute("username", request.getParameter("username"));
  434               request.setAttribute("password", request.getParameter("password"));
  435               request.setAttribute("password2", request.getParameter("password2"));
  436               request.setAttribute("protocol", request.getParameter("protocol"));
  437               request.setAttribute("port", request.getParameter("port"));
  438               addServer.include(request, response);
  439           } else if (action.equals("testEditServerConnection")) {
  440               request.setAttribute("name", request.getParameter("name"));
  441               request.setAttribute("ip", request.getParameter("ip"));
  442               request.setAttribute("port", request.getParameter("port"));
  443               request.setAttribute("username", request.getParameter("username"));
  444               request.setAttribute("password", request.getParameter("password"));
  445               request.setAttribute("password2", request.getParameter("password2"));
  446               request.setAttribute("server_id", request.getParameter("server_id"));
  447               request.setAttribute("snapshot", request.getParameter("snapshot"));
  448               request.setAttribute("retention", request.getParameter("retention"));
  449               addNodeAttribute(request);
  450               editServer.include(request, response);
  451           } else if (action.equals("disableEditServer")
  452                   || action.equals("enableEditServer")) {
  453               request.setAttribute("server_id", request.getParameter("server_id"));
  454               addNodeAttribute(request);
  455               editServer.include(request, response);
  456           } else if (action.equals("disableServer")
  457                   || action.equals("enableServer")) {
  458               request.setAttribute("server_id", request.getParameter("server_id"));
  459               normalView(request, response);
  460           } else {
  461               //TODO may need to avoid setting message
  462               normalView(request, response);
  463           }
  464           }//end request.isUserInRole("admin")
  465       }
  466   
  467       private void normalView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
  468           addAllViewsAttribute(request);
  469           addAllNodesAttribute(request);
  470           addAllGraphsAttribute(request);
  471   
  472           normalView.include(request, response);
  473       }
  474   
  475       private void addViewAttribute(RenderRequest request, boolean includeGraphs) throws PortletException {
  476           int viewId = Integer.parseInt(request.getParameter("view_id"));
  477           try {
  478               userTransaction.begin();
  479               try {
  480                   View view = entityManager.find(View.class, viewId);
  481                   request.setAttribute("view", view);
  482                   if (includeGraphs) {
  483                       List<Graph> graphs = view.getGraphs();
  484                       GraphsBuilder builder = new GraphsBuilder();
  485                       List<StatsGraph> statsGraphs = new ArrayList<StatsGraph>();
  486                       for (Graph graph: graphs) {
  487                          if(!graph.getNode().isEnabled())
  488                              continue;
  489                           StatsGraph statsGraph = builder.getStatsGraph(graph);
  490                           if (statsGraph != null) {
  491                               statsGraphs.add(statsGraph);
  492                           }
  493                       }
  494                       request.setAttribute("statsGraphs", statsGraphs);
  495                   }
  496               } finally {
  497                   userTransaction.commit();
  498               }
  499           } catch (Exception e) {
  500               throw new PortletException(e);
  501           }
  502       }
  503   
  504       private void addAllViewsAttribute(RenderRequest request) throws PortletException {
  505           try {
  506               userTransaction.begin();
  507               try {
  508                   List<View> views = entityManager.createNamedQuery("allViews").getResultList();
  509                   request.setAttribute("views", views);
  510               } finally {
  511                   userTransaction.commit();
  512               }
  513           } catch (Exception e) {
  514               throw new PortletException(e);
  515           }
  516       }
  517   
  518       private void addGraphAttribute(RenderRequest request) throws PortletException {
  519           try {
  520               userTransaction.begin();
  521               try {
  522                   String graphIdString = request.getParameter("graph_id");
  523                   int graphId = Integer.parseInt(graphIdString);
  524                   Graph graph = entityManager.find(Graph.class, graphId);
  525                   request.setAttribute("graph", graph);
  526               } finally {
  527                   userTransaction.commit();
  528               }
  529           } catch (Exception e) {
  530               throw new PortletException(e);
  531           }
  532       }
  533   
  534       private void addAllGraphsAttribute(RenderRequest request) throws PortletException {
  535           try {
  536               userTransaction.begin();
  537               try {
  538                   List<Graph> graphs = entityManager.createNamedQuery("allGraphs").getResultList();
  539                   request.setAttribute("graphs", graphs);
  540               } finally {
  541                   userTransaction.commit();
  542               }
  543           } catch (Exception e) {
  544               throw new PortletException(e);
  545           }
  546       }
  547   
  548       private void addNodeAttribute(RenderRequest request) throws PortletException {
  549           request.setAttribute("node", getNodeByName(request.getParameter("server_id")));
  550       }
  551   
  552       private Node getNodeByName(String name) throws PortletException {
  553           try {
  554               userTransaction.begin();
  555               try {
  556                   return entityManager.find(Node.class, name);
  557               } finally {
  558                   userTransaction.commit();
  559               }
  560           } catch (Exception e) {
  561               throw new PortletException(e);
  562           }
  563       }
  564   
  565       private void addAllNodesAttribute(RenderRequest request) throws PortletException {
  566           try {
  567               userTransaction.begin();
  568               try {
  569                   List<Node> nodes = entityManager.createNamedQuery("allNodes").getResultList();
  570                   request.setAttribute("nodes", nodes);
  571               } finally {
  572                   userTransaction.commit();
  573               }
  574           } catch (Exception e) {
  575               throw new PortletException(e);
  576           }
  577       }
  578   
  579       private void updateView(ActionRequest actionRequest,
  580                               ActionResponse actionResponse) {
  581           String view_id = actionRequest.getParameter("view_id");
  582           actionResponse.setRenderParameter("view_id", view_id);
  583   
  584           try {
  585               userTransaction.begin();
  586               try {
  587                   View view = entityManager.find(View.class, Integer.parseInt(view_id));
  588                   view.setName(actionRequest.getParameter("name"));
  589                   view.setDescription(actionRequest.getParameter("minxss_description"));
  590                   for(Graph graph: view.getGraphs())
  591                   {
  592                       for(View view_in : graph.getViews())
  593                       {
  594                           if(view_in.getId() == view.getId())
  595                           {//No grantee for that view and view_in have the same reference?
  596                               graph.getViews().remove(view_in);
  597                               break;
  598                           }
  599                       }
  600                   }
  601                   view.getGraphs().clear();
  602                   
  603                   String[] graphsArray = actionRequest.getParameterValues("graph_ids");
  604                   if (graphsArray != null) {
  605                       for (String graphIdString: graphsArray) {
  606                           int graphId = Integer.parseInt(graphIdString);
  607                           Graph graph = entityManager.find(Graph.class, graphId);
  608                           view.getGraphs().add(graph);
  609                           graph.getViews().add(view);
  610                       }
  611                   }
  612               } finally {
  613                   userTransaction.commit();
  614               }
  615               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg08", actionRequest.getParameter("name")));
  616           } catch (Exception e) {
  617           	addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg11", actionRequest.getParameter("name")), e.getMessage());
  618           }
  619   
  620       }
  621   
  622       private void addView(ActionRequest actionRequest,
  623                            ActionResponse actionResponse) {
  624           String name = actionRequest.getParameter("name");
  625           try {
  626               userTransaction.begin();
  627               try {
  628                   View view = new View();
  629                   view.setName(name);
  630                   view.setDescription(actionRequest.getParameter("minxss_description"));
  631                   String[] graphsArray = actionRequest.getParameterValues("graph_ids");
  632                   if (graphsArray != null) {
  633                       for (String graphIdString: graphsArray) {
  634                           int graphId = Integer.parseInt(graphIdString);
  635                           Graph graph = entityManager.find(Graph.class, graphId);
  636                           view.getGraphs().add(graph);
  637                           graph.getViews().add(view);
  638                       }
  639                   }
  640                   entityManager.persist(view);
  641               } finally {
  642                   userTransaction.commit();
  643               }
  644               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg09", name));
  645           } catch (Exception e) {
  646           	addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg12", name), e.getMessage());
  647           }
  648       }
  649   
  650       private void updateServer(ActionRequest actionRequest,
  651                                 ActionResponse actionResponse) {
  652           String server_id = actionRequest.getParameter("server_id");
  653           actionResponse.setRenderParameter("server_id", server_id);
  654   
  655           try {
  656               userTransaction.begin();
  657               try {
  658                   Node node = entityManager.find(Node.class, server_id);
  659                   node.setName(actionRequest.getParameter("name"));
  660                   node.setHost(actionRequest.getParameter("ip"));
  661                   node.setUserName(actionRequest.getParameter("username"));
  662                   String password = actionRequest.getParameter("password");
  663                   if (password != null && !password.equals("")) {
  664                       password = EncryptionManager.encrypt(password);
  665                       node.setPassword(password);
  666                   }
  667                   node.setPort(Integer.parseInt(actionRequest.getParameter("port")));
  668                   node.setProtocol(actionRequest.getParameter("protocol"));
  669                   //TODO retention??
  670                   String snapshot = actionRequest.getParameter("snapshot");
  671                   String retention = actionRequest.getParameter("retention");
  672                   if (snapshot != null && retention != null) {
  673                       MRCConnector connector = new MRCConnector(node);
  674                       connector.setSnapshotDuration(Long.parseLong(snapshot) * 1000 * 60);
  675                       connector.setSnapshotRetention(Integer.parseInt(retention));
  676                       connector.dispose();
  677                   }
  678               } finally {
  679                   userTransaction.commit();
  680               }
  681               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg10"));
  682           } catch (Exception e) {
  683           	addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg13"), e.getMessage());
  684           }
  685       }
  686   
  687       private void addServer(ActionRequest actionRequest,
  688                              ActionResponse actionResponse) {
  689           try {
  690               userTransaction.begin();
  691               String name = actionRequest.getParameter("name");
  692               String host = actionRequest.getParameter("ip");
  693               try {
  694                   Node node = new Node();
  695                   node.setName(name);
  696                   node.setHost(host);
  697                   node.setUserName(actionRequest.getParameter("username"));
  698                   String password = actionRequest.getParameter("password");
  699                   if (password != null && !password.equals("")) {
  700                       password = EncryptionManager.encrypt(password);
  701                       node.setPassword(password);
  702                   }
  703                   node.setPort(Integer.parseInt(actionRequest.getParameter("port")));
  704                   node.setProtocol(actionRequest.getParameter("protocol"));
  705                   entityManager.persist(node);
  706               } finally {
  707                   userTransaction.commit();
  708               }
  709               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg11", name, host));
  710           } catch (Exception e) {
  711           	addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg14"), e.getMessage());
  712           }
  713       }
  714   
  715       private void deleteServer(ActionRequest actionRequest,
  716                                 ActionResponse actionResponse) {
  717           String server_id = actionRequest.getParameter("server_id");
  718           actionResponse.setRenderParameter("server_id", server_id);
  719   
  720           try {
  721               userTransaction.begin();
  722               try {
  723                   Node node = entityManager.find(Node.class, server_id);
  724                   // check if there is any graph created against the node before delete it.
  725                   List<Graph> graphs = entityManager.createNamedQuery("graphsByNode").setParameter("name", node.getName()).getResultList();
  726                   if (!(graphs == null || graphs.isEmpty())) {
  727                       addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg20"));
  728                       return;
  729                   }
  730                   // check whether the snapshot query is enabled, if does, close it first
  731                   MRCConnector mrc = null;
  732                   try {
  733                       mrc = new MRCConnector(node);
  734                       if (mrc.isSnapshotRunning() == 1) {
  735                           if (mrc.stopSnapshotThread()) {
  736                               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg06", server_id));
  737                           } else {
  738                               addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg09", server_id));
  739                           }
  740                       }
  741                       
  742                   } catch (Exception e) {
  743                   } finally {
  744                       if(null != mrc)mrc.dispose();
  745                   }
  746                   entityManager.remove(node);
  747               } finally {
  748                   userTransaction.commit();
  749               }
  750               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg12"));
  751           } catch (Exception e) {
  752           	addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg15"), e.getMessage());
  753           }
  754       }
  755   
  756       private void deleteView(ActionRequest actionRequest,
  757                               ActionResponse actionResponse) {
  758           String view_id = actionRequest.getParameter("view_id");
  759           actionResponse.setRenderParameter("view_id", view_id);
  760   
  761           try {
  762               userTransaction.begin();
  763               try {
  764                   View view = entityManager.find(View.class, Integer.parseInt(view_id));
  765                   entityManager.remove(view);
  766               } finally {
  767                   userTransaction.commit();
  768               }
  769               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg13"));
  770           } catch (Exception e) {
  771           	addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg16"), e.getMessage());
  772           }
  773       }
  774   
  775       private void addGraph(ActionRequest actionRequest,
  776                             ActionResponse actionResponse) {
  777           Graph graph = new Graph();
  778   
  779           updateGraphFromRequest(actionRequest, graph);
  780           try {
  781               userTransaction.begin();
  782               try {
  783                   Node node = entityManager.find(Node.class, actionRequest.getParameter("server_id"));
  784                   graph.setNode(node);
  785                   entityManager.persist(graph);
  786               } finally {
  787                   userTransaction.commit();
  788               }
  789               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg14", graph.getGraphName1()));
  790           } catch (Exception e) {
  791           	addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg17"), e.getMessage());
  792           }
  793       }
  794   
  795       private void updateGraphFromRequest(ActionRequest actionRequest, Graph graph) {
  796           graph.setGraphName1(actionRequest.getParameter("name"));
  797           graph.setDescription(actionRequest.getParameter("minxss_description"));
  798           graph.setXlabel(actionRequest.getParameter("xlabel"));
  799           graph.setYlabel(actionRequest.getParameter("ylabel"));
  800           graph.setTimeFrame(Integer.parseInt(actionRequest.getParameter("timeframe")));
  801           graph.setMBeanName(actionRequest.getParameter("mbean"));
  802           graph.setDataName1(actionRequest.getParameter("dataname1"));
  803           graph.setData1operation(actionRequest.getParameter("data1operation").charAt(0));
  804   
  805           graph.setOperation(actionRequest.getParameter("operation"));
  806           if (graph.getOperation().equals("other")) {
  807               graph.setOperation(actionRequest.getParameter("othermath"));
  808           }
  809   
  810           graph.setShowArchive(actionRequest.getParameter("showArchive") != null
  811                   && actionRequest.getParameter("showArchive").equals("on"));
  812   
  813           graph.setDataName2(actionRequest.getParameter("dataname2"));
  814           graph.setData2operation(actionRequest.getParameter("data2operation") == null? 'A': actionRequest.getParameter("data2operation").charAt(0));
  815       }
  816   
  817       private void updateGraph(ActionRequest actionRequest,
  818                                ActionResponse actionResponse) {
  819           String graph_id = actionRequest.getParameter("graph_id");
  820           actionResponse.setRenderParameter("graph_id", graph_id);
  821           try {
  822               userTransaction.begin();
  823               try {
  824                   Graph graph = entityManager.find(Graph.class, Integer.parseInt(graph_id));
  825                   Node node = entityManager.find(Node.class, actionRequest.getParameter("server_id"));
  826                   graph.setNode(node);
  827                   updateGraphFromRequest(actionRequest, graph);
  828                   addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg15", graph.getGraphName1()));
  829               } finally {
  830                   userTransaction.commit();
  831               }
  832   
  833           } catch (Exception e) {
  834               log.info("error updating graph", e);
  835               addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg18"), e.getMessage());
  836           }
  837       }
  838   
  839       private void deleteGraph(ActionRequest actionRequest,
  840                                ActionResponse actionResponse) {
  841           String graph_id = actionRequest.getParameter("graph_id");
  842           actionResponse.setRenderParameter("graph_id", graph_id);
  843           try {
  844               userTransaction.begin();
  845               try {
  846                   Graph graph = entityManager.find(Graph.class, Integer.parseInt(graph_id));
  847                   entityManager.remove(graph);
  848                   addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg16", graph.getGraphName1()));
  849               } finally {
  850                   userTransaction.commit();
  851               }
  852   
  853           } catch (Exception e) {
  854               log.error("error deleting graph", e);
  855               addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg19"), e.getMessage());
  856           }
  857       }
  858       
  859       private void restoreData(ActionRequest actionRequest, ActionResponse actionResponse) {
  860           try {
  861               if (server == null) {
  862                   server = getWebServerType(PortletManager.getKernel().getGBean(WebContainer.class).getClass());
  863               }
  864               deleteDefaultServerView(actionRequest, actionResponse);
  865               initializeDefaultServerView(server);
  866               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg17"));
  867           } catch (Exception e) {
  868               log.error("error deleting graph", e);
  869               addErrorMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.errorMsg21"), e.getMessage());
  870           }
  871       }
  872   
  873   
  874       private void startTrackingMbean(String server_id, String mbean, PortletRequest request) {
  875           Node node;
  876           try {
  877               node = getNodeByName(server_id);
  878           } catch (PortletException e) {
  879               addInfoMessage(request, getLocalizedString(request, "mconsole.errorMsg04"), e.getMessage());
  880               return;
  881           }
  882           MRCConnector mrc =null;
  883           try {
  884               mrc = new MRCConnector(node);
  885           } catch (Exception e) {
  886               addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg05", node.getHost()), e.getMessage());
  887               return;
  888           }
  889   
  890           // tell the mrc server to start tracking an mbean
  891           try {
  892               if (mrc.startTrackingMbean(mbean)) {
  893                   String mbarr[] = mbean.split("name=");
  894                   addInfoMessage(request, getLocalizedString(request, "mconsole.infoMsg04", mbarr[1], node.getHost()));
  895               } else {
  896                   String mbarr[] = mbean.split("name=");
  897                   addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg06", mbarr[1], node.getHost()));
  898               }
  899           } catch (Exception e) {
  900               addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg06", mbean, node.getHost()), e.getMessage());
  901           }
  902           mrc.dispose();
  903       }
  904   
  905       private void stopTrackingMbean(String server_id, String mbean, PortletRequest request) {
  906           Node node;
  907           try {
  908               node = getNodeByName(server_id);
  909           } catch (PortletException e) {
  910               addInfoMessage(request, getLocalizedString(request, "mconsole.errorMsg04"), e.getMessage());
  911               return;
  912           }
  913           MRCConnector mrc;
  914           try {
  915               mrc = new MRCConnector(node);
  916           } catch (Exception e) {
  917               addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg05", node.getHost()), e.getMessage());
  918               return;
  919   
  920           }
  921           // tell the mrc-server to stop tracking some mbean
  922           try {
  923               if (mrc.stopTrackingMbean(mbean)) {
  924                   String mbarr[] = mbean.split("name=");
  925                   addInfoMessage(request, getLocalizedString(request, "mconsole.infoMsg05", mbarr[1], node.getHost()));
  926               } else {
  927                   String mbarr[] = mbean.split("name=");
  928                   addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg06", mbarr[1], node.getHost()));
  929               }
  930           } catch (Exception e) {
  931               addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg06", mbean, node.getHost()), e.getMessage());
  932           }
  933           mrc.dispose();
  934       }
  935   
  936       private void stopThread(String server_id, PortletRequest request) {
  937           Node node;
  938           try {
  939               node = getNodeByName(server_id);
  940           } catch (PortletException e) {
  941               log.info("error", e);
  942               addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg08", server_id), e.getMessage());
  943               return;
  944           }
  945           MRCConnector mrc = null;
  946           try {
  947               mrc = new MRCConnector(node);
  948               if (mrc.stopSnapshotThread()) {
  949                   addInfoMessage(request, getLocalizedString(request, "mconsole.infoMsg06", server_id));
  950               } else {
  951               	addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg09", server_id));
  952               }
  953           } catch (Exception e) {
  954           	addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg09", server_id), e.getMessage());
  955           } finally {
  956               if(null != mrc)
  957                   mrc.dispose();
  958           }
  959       }
  960   
  961       private void startThread(String server_id, Long snapshotDuration, PortletRequest request) {
  962           Node node;
  963           try {
  964               node = getNodeByName(server_id);
  965           } catch (PortletException e) {
  966               log.info("error", e);
  967               addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg08", server_id), e.getMessage());
  968               return;
  969           }
  970           MRCConnector mrc = null;
  971           try {
  972               mrc = new MRCConnector(node);
  973               if (mrc.startSnapshotThread(snapshotDuration)) {
  974                   addInfoMessage(request, getLocalizedString(request, "mconsole.infoMsg07", server_id));
  975               } else {
  976               	addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg10", server_id));
  977               }
  978           } catch (Exception e) {
  979           	addErrorMessage(request, getLocalizedString(request, "mconsole.errorMsg10", server_id), e.getMessage());
  980   
  981           } finally {
  982               if(null != mrc)mrc.dispose();
  983           }
  984       }
  985   
  986       @Override
  987       public void init(PortletConfig portletConfig) throws PortletException {
  988           super.init(portletConfig);
  989           normalView = portletConfig.getPortletContext().getRequestDispatcher(NORMALVIEW_JSP);
  990           viewViews = portletConfig.getPortletContext().getRequestDispatcher(VIEWVIEWS_JSP);
  991           viewServers = portletConfig.getPortletContext().getRequestDispatcher(VIEWSERVERS_JSP);
  992           viewGraphs = portletConfig.getPortletContext().getRequestDispatcher(VIEWGRAPHS_JSP);
  993           pageView = portletConfig.getPortletContext().getRequestDispatcher(PAGEVIEW_JSP);
  994           editView = portletConfig.getPortletContext().getRequestDispatcher(EDITVIEW_JSP);
  995           addView = portletConfig.getPortletContext().getRequestDispatcher(ADDVIEW_JSP);
  996           addGraph = portletConfig.getPortletContext().getRequestDispatcher(ADDGRAPH_JSP);
  997           editGraph = portletConfig.getPortletContext().getRequestDispatcher(EDITGRAPH_JSP);
  998           viewServer = portletConfig.getPortletContext().getRequestDispatcher(VIEWSERVER_JSP);
  999           editServer = portletConfig.getPortletContext().getRequestDispatcher(EDITSERVER_JSP);
 1000           addServer = portletConfig.getPortletContext().getRequestDispatcher(ADDSERVER_JSP);
 1001           helpView = portletConfig.getPortletContext().getRequestDispatcher(HELPVIEW_JSP);
 1002           editNormalView = portletConfig.getPortletContext().getRequestDispatcher(EDITNORMALVIEW_JSP);
 1003           try {
 1004               Context ctx = new InitialContext();
 1005               userTransaction = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
 1006               entityManager = (EntityManager) ctx.lookup("java:comp/env/jpa/monitoring");
 1007               server= getWebServerType(PortletManager.getKernel().getGBean(WebContainer.class).getClass());
 1008               if (!isPredefinedServerViewExist()) {
 1009                   initializeDefaultServerView(server);
 1010               }
 1011           } catch (NamingException e) {
 1012               throw new PortletException(e);
 1013           }catch (Exception e) {
 1014               throw new PortletException(e);
 1015           }
 1016       }
 1017   
 1018       @Override
 1019       public void destroy() {
 1020           normalView = null;
 1021           viewViews = null;
 1022           viewServers = null;
 1023           viewGraphs = null;
 1024           pageView = null;
 1025           editView = null;
 1026           addView = null;
 1027           addGraph = null;
 1028           editGraph = null;
 1029           viewServer = null;
 1030           editServer = null;
 1031           addServer = null;
 1032           helpView = null;
 1033           editNormalView = null;
 1034           super.destroy();
 1035       }
 1036   
 1037       private void initializeDefaultServerView(String server) throws Exception {
 1038           if (server == null) {
 1039               throw new Exception("Unrecognized web server type");
 1040           } else if (server.equalsIgnoreCase("tomcat")) {
 1041               initializeDefaultTomatServerView();
 1042           } else if (server.equalsIgnoreCase("jetty")) {
 1043               initializeDefaultJettyServerView();
 1044           }
 1045       }
 1046       
 1047       private String getObjectNameByShortName(String shortName) {
 1048           try {
 1049               Object targetGBean = PortletManager.getKernel().getGBean(shortName);
 1050               return PortletManager.getKernel().getAbstractNameFor(targetGBean).getObjectName().getCanonicalName();
 1051           } catch (Exception e) {
 1052               log.error("Fail to find the gbean object for the short name " + shortName);
 1053               return null;
 1054           }
 1055       }
 1056   
 1057       private void initializeDefaultTomatServerView() throws Exception {
 1058           String tomcatWebConnectorObjectName = getObjectNameByShortName("TomcatWebConnector");
 1059           String tomcatWebSSLConnectorObjectName = getObjectNameByShortName("TomcatWebSSLConnector");
 1060           try {
 1061               userTransaction.begin();
 1062               Node node = persistDefaultServer();
 1063               if (tomcatWebConnectorObjectName != null) {
 1064                   Graph[] webConnectorGraphs = new Graph[15];
 1065                   webConnectorGraphs[0] = createGraph(node, "JVM Heap Size Current", "JVM Heap Size Current", "60", getObjectNameByShortName("JVM"), "JVM Heap Size Current", "JVM Heap Size Current", "Time", "A", "", "A", null, null);
 1066                   webConnectorGraphs[1] = createGraph(node, "Active Request Count", "Active Request Count", "60", tomcatWebConnectorObjectName, "Active Request Count", "Active Request Count", "Time", "A", "", "A", null, null);
 1067                   webConnectorGraphs[2] = createGraph(node, "Busy Threads Max", "Busy Threads Max", "60", tomcatWebConnectorObjectName, "Busy Threads Max", "Busy Threads Max", "Time", "A", "", "A", null, null);
 1068                   webConnectorGraphs[3] = createGraph(node, "Busy Threads Current", "Busy Threads Current", "60", tomcatWebConnectorObjectName, "Busy Threads Current", "Busy Threads Current", "Time", "A", "", "A", null, null);
 1069                   webConnectorGraphs[4] = createGraph(node, "Busy Threads Min", "Busy Threads Min", "60", tomcatWebConnectorObjectName, "Busy Threads Min", "Busy Threads Min", "Time", "A", "", "A", null, null);
 1070                   webConnectorGraphs[5] = createGraph(node, "Bytes Received", "Bytes Received", "60", tomcatWebConnectorObjectName, "Bytes Received", "Bytes Received", "Time", "A", "", "A", null, null);
 1071                   webConnectorGraphs[6] = createGraph(node, "Bytes Sent", "Bytes Sent", "60", tomcatWebConnectorObjectName, "Bytes Sent", "Bytes Sent", "Time", "A", "", "A", null, null);
 1072                   webConnectorGraphs[7] = createGraph(node, "Error Count", "Error Count", "60", tomcatWebConnectorObjectName, "Error Count", "Error Count", "Time", "A", "", "A", null, null);
 1073                   webConnectorGraphs[8] = createGraph(node, "Open Connections Current", "Open Connections Current", "60", tomcatWebConnectorObjectName, "Open Connections Current", "Open Connections Current", "Time", "A", "", "A", null, null);
 1074                   webConnectorGraphs[9] = createGraph(node, "Open Connections Max", "Open Connections Max", "60", tomcatWebConnectorObjectName, "Open Connections Max", "Open Connections Max", "Time", "A", "", "A", null, null);
 1075                   webConnectorGraphs[10] = createGraph(node, "Open Connections Min", "Open Connections Min", "60", tomcatWebConnectorObjectName, "Open Connections Min", "Open Connections Min", "Time", "A", "", "A", null, null);
 1076                   webConnectorGraphs[11] = createGraph(node, "Request Time CurrentTime", "Request Time CurrentTime", "60", tomcatWebConnectorObjectName, "Request Time CurrentTime", "Request Time CurrentTime", "Time", "A", "", "A", null, null);
 1077                   webConnectorGraphs[12] = createGraph(node, "Request Time MaxTime", "Request Time MaxTime", "60", tomcatWebConnectorObjectName, "Request Time MaxTime", "Request Time MaxTime", "Time", "A", "", "A", null, null);
 1078                   webConnectorGraphs[13] = createGraph(node, "Request Time MinTime", "Request Time MinTime", "60", tomcatWebConnectorObjectName, "Request Time MinTime", "Request Time MinTime", "Time", "A", "", "A", null, null);
 1079                   webConnectorGraphs[14] = createGraph(node, "Request Time TotalTime", "Request Time TotalTime", "60", tomcatWebConnectorObjectName, "Request Time TotalTime", "Request Time TotalTime", "Time", "A", "", "A", null, null);
 1080                   persistView("TomcatWebConnector View", "TomcatWebConnector View", webConnectorGraphs);
 1081               }
 1082               if (tomcatWebSSLConnectorObjectName != null) {
 1083                   Graph[] webSSLConnectorGraphs = new Graph[15];               
 1084                   webSSLConnectorGraphs[0] = createGraph(node, "JVM Heap Size Current", "JVM Heap Size Current", "60", getObjectNameByShortName("JVM"), "JVM Heap Size Current", "JVM Heap Size Current", "Time", "A", "", "A", "", null);
 1085                   webSSLConnectorGraphs[1] = createGraph(node, "SSL Active Request Count", "Active Request Count", "60", tomcatWebSSLConnectorObjectName, "Active Request Count", "Active Request Count", "Time", "A", "", "A", "", null);
 1086                   webSSLConnectorGraphs[2] = createGraph(node, "SSL Busy Threads Current", "Busy Threads Current", "60", tomcatWebSSLConnectorObjectName, "Busy Threads Current", "Busy Threads Current", "Time", "A", "", "A", "", null);
 1087                   webSSLConnectorGraphs[3] = createGraph(node, "SSL Busy Threads Max", "Busy Threads Max", "60", tomcatWebSSLConnectorObjectName, "Busy Threads Max", "Busy Threads Max", "Time", "A", "", "A", "", null);
 1088                   webSSLConnectorGraphs[4] = createGraph(node, "SSL Busy Threads Min", "Busy Threads Min", "60", tomcatWebSSLConnectorObjectName, "Busy Threads Min", "Busy Threads Min", "Time", "A", "", "A", "", null);
 1089                   webSSLConnectorGraphs[5] = createGraph(node, "SSL Bytes Received", "Bytes Received", "60", tomcatWebSSLConnectorObjectName, "Bytes Received", "Bytes Received", "Time", "A", "", "A", "", null);
 1090                   webSSLConnectorGraphs[6] = createGraph(node, "SSL Bytes Sent", "Bytes Sent", "60", tomcatWebSSLConnectorObjectName, "Bytes Sent", "Bytes Sent", "Time", "A", "", "A", "", null);
 1091                   webSSLConnectorGraphs[7] = createGraph(node, "SSL Error Count", "Error Count", "60", tomcatWebSSLConnectorObjectName, "Error Count", "Error Count", "Time", "A", "", "A", "", null);
 1092                   webSSLConnectorGraphs[8] = createGraph(node, "SSL Open Connections Current", "Open Connections Current", "60", tomcatWebSSLConnectorObjectName, "Open Connections Current", "Open Connections Current", "Time", "A", "", "A", "", null);
 1093                   webSSLConnectorGraphs[9] = createGraph(node, "SSL Open Connections Max", "Open Connections Max", "60", tomcatWebSSLConnectorObjectName, "Open Connections Max", "Open Connections Max", "Time", "A", "", "A", "", null);
 1094                   webSSLConnectorGraphs[10] = createGraph(node, "SSL Open Connections Min", "Open Connections Min", "60", tomcatWebSSLConnectorObjectName, "Open Connections Min", "Open Connections Min", "Time", "A", "", "A", "", null);
 1095                   webSSLConnectorGraphs[11] = createGraph(node, "SSL Request Time CurrentTime", "Request Time CurrentTime", "60", tomcatWebSSLConnectorObjectName, "Request Time CurrentTime", "Request Time CurrentTime", "Time", "A", "", "A", "", null);
 1096                   webSSLConnectorGraphs[12] = createGraph(node, "SSL Request Time MaxTime", "Request Time MaxTime", "60", tomcatWebSSLConnectorObjectName, "Request Time MaxTime", "Request Time MaxTime", "Time", "A", "", "A", "", null);
 1097                   webSSLConnectorGraphs[13] = createGraph(node, "SSL Request Time MinTime", "Request Time MinTime", "60", tomcatWebSSLConnectorObjectName, "Request Time MinTime", "Request Time MinTime", "Time", "A", "", "A", "", null);
 1098                   webSSLConnectorGraphs[14] = createGraph(node, "SSL Request Time TotalTime", "Request Time TotalTime", "60", tomcatWebSSLConnectorObjectName, "Request Time TotalTime", "Request Time TotalTime", "Time", "A", "", "A", "", null);               
 1099                   persistView("TomcatWebSSLConnector View", "TomcatWebSSLConnector View", webSSLConnectorGraphs);
 1100               }
 1101           } catch (Exception e) {
 1102               userTransaction.rollback();
 1103               throw e;
 1104           } finally {
 1105               userTransaction.commit();
 1106           }
 1107       }
 1108       
 1109       private void initializeDefaultJettyServerView() throws Exception {
 1110           String jettyWebConnectorObjectName = getObjectNameByShortName("JettyWebConnector");
 1111           String jettyWebSSLConnectorObjectName = getObjectNameByShortName("JettySSLConnector");
 1112           try {
 1113               userTransaction.begin();
 1114               Node node = persistDefaultServer();
 1115               if (jettyWebConnectorObjectName != null) {
 1116                   Graph[] webConnectorGraphs = new Graph[12];
 1117                   webConnectorGraphs[0] = createGraph(node, "JVM Heap Size Current", "JVM Heap Size Current", "60", getObjectNameByShortName("JVM"), "JVM Heap Size Current", "JVM Heap Size Current", "Time", "A", "", "A", "", null);
 1118                   webConnectorGraphs[1] = createGraph(node, "Connections Duration Count", "Connections Duration Count", "60", jettyWebConnectorObjectName, "Connections Duration Count", "Connections Duration Count", "Time", "A", "", "A", "", null);
 1119                   webConnectorGraphs[2] = createGraph(node, "Connections Duration MaxTime", "Connections Duration MaxTime", "60", jettyWebConnectorObjectName, "Connections Duration MaxTime", "Connections Duration MaxTime", "Time", "A", "", "A", "", null);
 1120                   webConnectorGraphs[3] = createGraph(node, "Connections Duration MinTime", "Connections Duration MinTime", "60", jettyWebConnectorObjectName, "Connections Duration MinTime", "Connections Duration MinTime", "Time", "A", "", "A", "", null);
 1121                   webConnectorGraphs[4] = createGraph(node, "Connections Duration TotalTime", "Connections Duration TotalTime", "60", jettyWebConnectorObjectName, "Connections Duration TotalTime", "Connections Duration TotalTime", "Time", "A", "", "A", "", null);
 1122                   webConnectorGraphs[5] = createGraph(node, "Connections Request Current", "Connections Request Current", "60", jettyWebConnectorObjectName, "Connections Request Current", "Connections Request Current", "Time", "A", "", "A", "", null);
 1123                   webConnectorGraphs[6] = createGraph(node, "Connections Request Max", "Connections Request Max", "60", jettyWebConnectorObjectName, "Connections Request Max", "Connections Request Max", "Time", "A", "", "A", "", null);
 1124                   webConnectorGraphs[7] = createGraph(node, "Connections Request Min", "Connections Request Min", "60", jettyWebConnectorObjectName, "Connections Request Min", "Connections Request Min", "Time", "A", "", "A", "", null);
 1125                   webConnectorGraphs[8] = createGraph(node, "Open Connections Current", "Open Connections Current", "60", jettyWebConnectorObjectName, "Open Connections Current", "Open Connections Current", "Time", "A", "", "A", "", null);
 1126                   webConnectorGraphs[9] = createGraph(node, "Open Connections Max", "Open Connections Max", "60", jettyWebConnectorObjectName, "Open Connections Max", "Open Connections Max", "Time", "A", "", "A", "", null);
 1127                   webConnectorGraphs[10] = createGraph(node, "Open Connections Min", "Open Connections Min", "60", jettyWebConnectorObjectName, "Open Connections Min", "Open Connections Min", "Time", "A", "", "A", "", null);
 1128                   webConnectorGraphs[11] = createGraph(node, "Request Time CurrentTime", "Request Time CurrentTime", "60", jettyWebConnectorObjectName, "Request Time CurrentTime", "Request Time CurrentTime", "Time", "A", "", "A", "", null);
 1129                   persistView("JettyWebConnector View", "JettyWebConnector View", webConnectorGraphs);
 1130               }
 1131               if (jettyWebSSLConnectorObjectName != null) {
 1132                   Graph[] webSSLConnectorGraphs = new Graph[12];
 1133                   webSSLConnectorGraphs[0] = createGraph(node, "JVM Heap Size Current", "JVM Heap Size Current", "60", getObjectNameByShortName("JVM"), "JVM Heap Size Current", "JVM Heap Size Current", "Time", "A", "", "A", "", null);
 1134                   webSSLConnectorGraphs[1] = createGraph(node, "Connections Duration Count", "Connections Duration Count", "60", jettyWebSSLConnectorObjectName, "Connections Duration Count", "Connections Duration Count", "Time", "A", "", "A", "", null);
 1135                   webSSLConnectorGraphs[2] = createGraph(node, "Connections Duration MaxTime", "Connections Duration MaxTime", "60", jettyWebSSLConnectorObjectName, "Connections Duration MaxTime", "Connections Duration MaxTime", "Time", "A", "", "A", "", null);
 1136                   webSSLConnectorGraphs[3] = createGraph(node, "Connections Duration MinTime", "Connections Duration MinTime", "60", jettyWebSSLConnectorObjectName, "Connections Duration MinTime", "Connections Duration MinTime", "Time", "A", "", "A", "", null);
 1137                   webSSLConnectorGraphs[4] = createGraph(node, "Connections Duration TotalTime", "Connections Duration TotalTime", "60", jettyWebSSLConnectorObjectName, "Connections Duration TotalTime", "Connections Duration TotalTime", "Time", "A", "", "A", "", null);
 1138                   webSSLConnectorGraphs[5] = createGraph(node, "Connections Request Current", "Connections Request Current", "60", jettyWebSSLConnectorObjectName, "Connections Request Current", "Connections Request Current", "Time", "A", "", "A", "", null);
 1139                   webSSLConnectorGraphs[6] = createGraph(node, "Connections Request Max", "Connections Request Max", "60", jettyWebSSLConnectorObjectName, "Connections Request Max", "Connections Request Max", "Time", "A", "", "A", "", null);
 1140                   webSSLConnectorGraphs[7] = createGraph(node, "Connections Request Min", "Connections Request Min", "60", jettyWebSSLConnectorObjectName, "Connections Request Min", "Connections Request Min", "Time", "A", "", "A", "", null);
 1141                   webSSLConnectorGraphs[8] = createGraph(node, "Open Connections Current", "Open Connections Current", "60", jettyWebSSLConnectorObjectName, "Open Connections Current", "Open Connections Current", "Time", "A", "", "A", "", null);
 1142                   webSSLConnectorGraphs[9] = createGraph(node, "Open Connections Max", "Open Connections Max", "60", jettyWebSSLConnectorObjectName, "Open Connections Max", "Open Connections Max", "Time", "A", "", "A", "", null);
 1143                   webSSLConnectorGraphs[10] = createGraph(node, "Open Connections Min", "Open Connections Min", "60", jettyWebSSLConnectorObjectName, "Open Connections Min", "Open Connections Min", "Time", "A", "", "A", "", null);
 1144                   webSSLConnectorGraphs[11] = createGraph(node, "Request Time CurrentTime", "Request Time CurrentTime", "60", jettyWebSSLConnectorObjectName, "Request Time CurrentTime", "Request Time CurrentTime", "Time", "A", "", "A", "", null);
 1145                   persistView("JettySSLConnector View", "JettySSLConnector View", webSSLConnectorGraphs);
 1146               }
 1147           } catch (Exception e) {
 1148               userTransaction.rollback();
 1149               throw e;
 1150           } finally {
 1151               userTransaction.commit();
 1152           }
 1153       }
 1154       
 1155       private Node persistDefaultServer() throws Exception {
 1156           Node node = new Node();
 1157           node.setName("Default Server");
 1158           node.setHost("localhost");
 1159           node.setUserName("");
 1160           node.setPassword("");
 1161           node.setPort(1099);
 1162           node.setProtocol("jmx");
 1163           entityManager.persist(node);
 1164           return node;
 1165       }
 1166       
 1167       private Graph createGraph(Node node, String name, String description, String timeframe, String mbean, String dataname1, String xlabel, String ylabel, String data1operation, String operation,
 1168               String data2operation, String dataname2, String showArchive) throws Exception {
 1169           Graph graph = new Graph();
 1170           graph.setNode(node);
 1171           graph.setGraphName1(name);
 1172           graph.setDescription(description);
 1173           graph.setXlabel(xlabel);
 1174           graph.setYlabel(ylabel);
 1175           graph.setTimeFrame(Integer.parseInt(timeframe));
 1176           graph.setMBeanName(mbean);
 1177           graph.setDataName1(dataname1);
 1178           graph.setData1operation(data1operation.charAt(0));
 1179           graph.setOperation(operation);
 1180           graph.setShowArchive(showArchive != null && showArchive.equals("on"));
 1181           graph.setDataName2(dataname2);
 1182           graph.setData2operation(data2operation == null ? 'A' : data2operation.charAt(0));
 1183           return graph;
 1184       }
 1185       
 1186       private View persistView(String name, String description, Graph[] graphsArray) throws Exception {
 1187           View view = new View();
 1188           view.setName(name);
 1189           view.setDescription(description);
 1190           if (graphsArray != null) {
 1191               for (Graph graph : graphsArray) {
 1192                   view.getGraphs().add(graph);
 1193                   graph.getViews().add(view);
 1194               }
 1195           }
 1196           entityManager.persist(view);
 1197           return view;
 1198       }
 1199       
 1200       private boolean isPredefinedServerViewExist() {
 1201           Node node = entityManager.find(Node.class, "Default Server");
 1202           return node != null;
 1203       }
 1204       
 1205       private void deleteDefaultServerView(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
 1206           try {
 1207               userTransaction.begin();
 1208               Node node = entityManager.find(Node.class, "Default Server");
 1209               if (node != null) {
 1210                   List<Graph> graphs = entityManager.createNamedQuery("graphsByNode").setParameter("name", node.getName()).getResultList();
 1211                   if (!(graphs == null || graphs.isEmpty())) {
 1212                       for (Graph graph : graphs) {
 1213                           List<View> views = graph.getViews();
 1214                           for (View view : views) {
 1215                               entityManager.remove(view);
 1216                           }
 1217                           entityManager.remove(graph);
 1218                       }
 1219                   }
 1220                   MRCConnector mrc = null;
 1221                   try {
 1222                       mrc = new MRCConnector(node);
 1223                       if (mrc.isSnapshotRunning() == 1) {
 1224                           if (!mrc.stopSnapshotThread()) {
 1225                               addInfoMessage(actionRequest, getLocalizedString(actionRequest, "mconsole.infoMsg06", node));
 1226                           }
 1227                       }
 1228                   } finally {
 1229                       if (null != mrc)
 1230                           mrc.dispose();
 1231                   }
 1232                   entityManager.remove(node);
 1233               }
 1234               userTransaction.commit();
 1235           } catch (Exception e) {
 1236               userTransaction.rollback();
 1237               throw e;
 1238           }
 1239       }
 1240   
 1241       
 1242       
 1243   }

Home » geronimo-2.2-source-release » org.apache.geronimo.monitoring.console » [javadoc | source]