org.glassfish.admingui.common.handlers.MonitoringHandlers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of payara-micro Show documentation
Show all versions of payara-micro Show documentation
Micro Distribution of the Payara Project
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.admingui.common.handlers;
import java.io.UnsupportedEncodingException;
import org.glassfish.admingui.common.util.GuiUtil;
import com.sun.jsftemplating.annotation.Handler;
import com.sun.jsftemplating.annotation.HandlerInput;
import com.sun.jsftemplating.annotation.HandlerOutput;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import java.net.URLEncoder;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Locale;
import java.util.Date;
import java.util.ListIterator;
import java.util.logging.Level;
import org.glassfish.admingui.common.util.RestResponse;
import org.glassfish.admingui.common.util.RestUtil;
/**
*
* @author Ana
*/
public class MonitoringHandlers {
@Handler(id = "gf.getMonitorLevels",
input = {
@HandlerInput(name = "endpoint", type = String.class, required = true)},
output = {
@HandlerOutput(name = "monitorCompList", type = List.class)
})
public static void getMonitorLevels(HandlerContext handlerCtx) {
String endpoint = (String) handlerCtx.getInputValue("endpoint");
List result = new ArrayList();
try {
String monitoringLevelsEndPoint = endpoint + "/monitoring-service/module-monitoring-levels";
Map attrs = RestUtil.getEntityAttrs(monitoringLevelsEndPoint, "entity");
for(Map.Entry e : attrs.entrySet()){
Map oneRow = new HashMap();
String name = null;
String moduleName=e.getKey();
//workaround for GLASSFISH-19722. Skip any cloud module.
if(moduleName.startsWith("cloud")){
continue;
}
ListIterator ni = monDisplayList.listIterator();
ListIterator vi = monNamesList.listIterator();
while (ni.hasNext() && vi.hasNext()) {
String dispName = (String) ni.next();
String value = (String) vi.next();
if ((moduleName.equals(value))) {
name = dispName;
break;
}
}
if (name == null) {
name = moduleName;
}
oneRow.put("monCompName", name);
oneRow.put("attrName", moduleName);
oneRow.put("level", e.getValue());
oneRow.put("selected", false);
result.add(oneRow);
}
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
handlerCtx.setOutputValue("monitorCompList", result);
}
/*
* This handler returns a list of statistical data for an endpoint.
* Useful for populating table
*/
@Handler(id = "getStats",
input = {
@HandlerInput(name = "endpoint", type = String.class, required = true),
@HandlerInput(name = "statType", type = String.class),
@HandlerInput(name = "type", type = String.class)},
output = {
@HandlerOutput(name = "result", type = List.class),
@HandlerOutput(name = "hasStats", type = Boolean.class)})
public static void getStats(HandlerContext handlerCtx) {
String endpoint = (String) handlerCtx.getInputValue("endpoint");
String statType = (String) handlerCtx.getInputValue("statType");
String type = (String) handlerCtx.getInputValue("type");
Locale locale = GuiUtil.getLocale();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale);
//NumberFormat nf = NumberFormat.getNumberInstance(locale);
List result = new ArrayList();
try {
//This check is to get the correct type of statistics.
if ((type == null || statType == null) || type.equals(statType)) {
if (RestUtil.doesProxyExist(endpoint)) {
Map stats = getMonitoringStatInfo(endpoint);
//Jersey monitoring data format
if (statType != null && statType.equals("jersey")) {
Map jerseyStats = new HashMap();
for(Map.Entry e : stats.entrySet()){
Map jerseyStat = (Map) e.getValue();
if (jerseyStat != null) {
jerseyStats.putAll(jerseyStat);
}
}
stats = jerseyStats;
}
for(Map.Entry e : stats.entrySet()){
if (!(e.getValue().getClass().equals(HashMap.class))) {
continue;
}
Map monAttrs = (Map) e.getValue();
Map statMap = new HashMap();
String val = "";
String details = "--";
String desc = "--";
String start = "--";
String last = "--";
String unit = "";
String mname = null;
String runtimes = null;
String queuesize = null;
String thresholds = "--";
if (!monAttrs.isEmpty()) {
if (monAttrs.containsKey("name")) {
mname = (String) monAttrs.get("name");
} else if (monAttrs.containsKey("appname")) {
mname = (String) monAttrs.get("appname");
}
unit = (String) monAttrs.get("unit");
desc = (String) monAttrs.get("description");
Long lastTime = (Long) monAttrs.get("lastsampletime");
if (lastTime != -1) {
last = df.format(new Date(lastTime));
}
Long startTime = (Long) monAttrs.get("starttime");
if (startTime != -1) {
start = df.format(new Date(startTime));
}
if (monAttrs.containsKey("count")) {
val = monAttrs.get("count") + " " + unit;
} else if (monAttrs.containsKey("current")) {
if (unit != null) {
if (unit.equals("String")) {
if (mname.equals("LiveThreads")) {
String str = (String) monAttrs.get("current");
val = formatStringForDisplay(str);
} else {
val = (String) monAttrs.get("current");
}
} else if (unit.equals("List")) {
String str = (String) monAttrs.get("current");
String formatStr = formatActiveIdsForDisplay(str);
if (!formatStr.isEmpty() && !formatStr.equals("")) {
val = formatStr;
}
} else {
Long currentVal = (Long) monAttrs.get("current");
val = currentVal + unit;
}
}
} else if (monAttrs.containsKey("applicationtype")) {
val = (String) monAttrs.get("applicationtype");
}
//Update the details
if (monAttrs.containsKey("appName")) {
details = (GuiUtil.getMessage("msg.AppName") + ": " + monAttrs.get("appName") + "
");
}
if (monAttrs.containsKey("appname")) {
details = (GuiUtil.getMessage("msg.AppName") + ": " + monAttrs.get("appname") + "
");
}
if (monAttrs.containsKey("environment")) {
details = details + (GuiUtil.getMessage("msg.Environment") + ": " + monAttrs.get("environment") + "
");
}
if (monAttrs.containsKey("address")) {
details = details + (GuiUtil.getMessage("msg.Address") + ": " + monAttrs.get("address") + "
");
}
if (monAttrs.containsKey("deploymenttype")) {
details = details + (GuiUtil.getMessage("msg.DepType") + ": " + monAttrs.get("deploymenttype") + "
");
}
if (monAttrs.containsKey("endpointname")) {
details = details + (GuiUtil.getMessage("msg.EndPointName") + ": " + monAttrs.get("endpointname") + "
");
}
if (monAttrs.containsKey("classname")) {
details = (GuiUtil.getMessage("msg.ClassName") + ": " + monAttrs.get("classname") + "
");
}
if (monAttrs.containsKey("impltype")) {
details = details + (GuiUtil.getMessage("msg.ImplClass") + ": " + monAttrs.get("implclass") + "
");
}
if (monAttrs.containsKey("implclass") && monAttrs.containsKey("impltype")) {
details = details + (GuiUtil.getMessage("msg.ImplType") + ": " + monAttrs.get("impltype") + "
");
}
if (monAttrs.containsKey("namespace")) {
details = details + (GuiUtil.getMessage("msg.NameSpace") + ": " + monAttrs.get("namespace") + "
");
}
if (monAttrs.containsKey("portname")) {
details = details + (GuiUtil.getMessage("msg.PortName") + ": " + monAttrs.get("portname") + "
");
}
if (monAttrs.containsKey("servicename")) {
details = details + (GuiUtil.getMessage("msg.ServiceName") + ": " + monAttrs.get("servicename") + "
");
}
if (monAttrs.containsKey("tester")) {
details = details + (GuiUtil.getMessage("msg.Tester") + ": " + monAttrs.get("tester") + "
");
}
if (monAttrs.containsKey("wsdl")) {
details = details + (GuiUtil.getMessage("msg.WSDL") + ": " + monAttrs.get("wsdl") + "
");
}
if (monAttrs.containsKey("maxtime")) {
details = (GuiUtil.getMessage("msg.MaxTime") + ": " + monAttrs.get("maxtime") + " " + unit + "
");
}
if (monAttrs.containsKey("mintime")) {
details = details + (GuiUtil.getMessage("msg.MinTime") + ": " + monAttrs.get("mintime") + " " + unit + "
");
}
if (monAttrs.containsKey("totaltime")) {
details = details + (GuiUtil.getMessage("msg.TotalTime") + ": " + monAttrs.get("totaltime") + " " + unit + "
");
}
if (monAttrs.containsKey("highwatermark")) {
details = (GuiUtil.getMessage("msg.HWaterMark") + ": " + monAttrs.get("highwatermark") + " " + unit + "
");
}
if (monAttrs.containsKey("lowwatermark")) {
details = details + (GuiUtil.getMessage("msg.LWaterMark") + ": " + monAttrs.get("lowwatermark") + " " + unit + "
");
}
if (monAttrs.containsKey("activeruntimes")) {
runtimes = (String) monAttrs.get("activeruntimes");
}
if (monAttrs.containsKey("queuesize")) {
queuesize = (String) monAttrs.get("queuesize");
}
if (monAttrs.containsKey("hardmaximum") && monAttrs.get("hardmaximum") != null) {
val = monAttrs.get("hardmaximum") + " " + "hard max " + "
" + monAttrs.get("hardminimum") + " " + "hard min";
}
if (monAttrs.containsKey("newthreshold") && monAttrs.get("newThreshold") != null) {
thresholds = monAttrs.get("newthreshold") + " " + "new " + "
" + monAttrs.get("queuedownthreshold") + " " + "queue down";
}
if (monAttrs.containsKey("queuesize") && monAttrs.containsKey("environment")) {
details = details + monAttrs.get("environment");
}
statMap.put("name", mname);
statMap.put("startTime", start);
statMap.put("lastTime", last);
statMap.put("description", desc);
statMap.put("value", (val == null) ? "" : val);
statMap.put("details", details);
statMap.put("thresholds", thresholds);
statMap.put("queueSize", (queuesize == null) ? "--" : queuesize);
statMap.put("runtimes", (runtimes == null) ? "--" : runtimes);
result.add(statMap);
}
}
}
}
handlerCtx.setOutputValue("result", result);
handlerCtx.setOutputValue("hasStats", (result.size() == 0) ? false : true);
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
}
@Handler(id = "updateMonitorLevels",
input = {
@HandlerInput(name = "allRows", type = List.class, required = true),
@HandlerInput(name = "endpoint", type = String.class)})
public static void updateMonitorLevels(HandlerContext handlerCtx) {
String endpoint = (String) handlerCtx.getInputValue("endpoint");
List