Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.
*/
// Portions Copyright [2018-2019] Payara Foundation and/or affiliates
package org.glassfish.admingui.common.handlers;
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.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.StringJoiner;
import java.util.logging.Level;
import org.glassfish.admingui.common.util.GuiUtil;
import org.glassfish.admingui.common.util.RestUtil;
/**
* Handlers for processing monitoring in the admin console
* @author Ana
*/
public class MonitoringHandlers {
final private static List levels = new ArrayList();
static {
levels.add("OFF");
levels.add("LOW");
levels.add("HIGH");
}
//monitoring modulemonitoring.module names
public static final String JVM = GuiUtil.getCommonMessage("monitoring.module.Jvm");
public static final String WEB_CONTAINER = GuiUtil.getCommonMessage("monitoring.module.Web");
public static final String HTTP_SERVICE = GuiUtil.getCommonMessage("monitoring.module.Http");
public static final String THREAD_POOL = GuiUtil.getCommonMessage("monitoring.module.ThreadPool");
public static final String JDBC_CONNECTION_POOL = GuiUtil.getCommonMessage("monitoring.module.Jdbc");
public static final String CONNECTOR_CONNECTION_POOL = GuiUtil.getCommonMessage("monitoring.module.Connector");
public static final String EJB_CONTAINER = GuiUtil.getCommonMessage("monitoring.module.Ejb");
public static final String TRANSACTION_SERVICE = GuiUtil.getCommonMessage("monitoring.module.TransactionService");
public static final String ORB = GuiUtil.getCommonMessage("monitoring.module.Orb");
public static final String CONNECTOR_SERVICE = GuiUtil.getCommonMessage("monitoring.module.ConnectorService");
public static final String JMS_SERVICE = GuiUtil.getCommonMessage("monitoring.module.JmsService");
public static final String WEB_SERVICES_CONTAINER = GuiUtil.getCommonMessage("monitoring.module.WebServices");
public static final String JPA = GuiUtil.getCommonMessage("monitoring.module.Jpa");
public static final String SECURITY = GuiUtil.getCommonMessage("monitoring.module.Security");
public static final String JERSEY = GuiUtil.getCommonMessage("monitoring.module.Jersey");
public static final String DEPLOYMENT = GuiUtil.getCommonMessage("monitoring.module.Deployment");
final private static List monDisplayList = new ArrayList();
static {
monDisplayList.add(JVM);
monDisplayList.add(WEB_CONTAINER);
monDisplayList.add(HTTP_SERVICE);
monDisplayList.add(THREAD_POOL);
monDisplayList.add(JDBC_CONNECTION_POOL);
monDisplayList.add(CONNECTOR_CONNECTION_POOL);
monDisplayList.add(EJB_CONTAINER);
monDisplayList.add(TRANSACTION_SERVICE);
monDisplayList.add(ORB);
monDisplayList.add(CONNECTOR_SERVICE);
monDisplayList.add(JMS_SERVICE);
monDisplayList.add(WEB_SERVICES_CONTAINER);
monDisplayList.add(JPA);
monDisplayList.add(SECURITY);
monDisplayList.add(JERSEY);
monDisplayList.add(DEPLOYMENT);
}
final private static List monNamesList = new ArrayList();
static {
monNamesList.add("jvm");
monNamesList.add("webContainer");
monNamesList.add("httpService");
monNamesList.add("threadPool");
monNamesList.add("jdbcConnectionPool");
monNamesList.add("connectorConnectionPool");
monNamesList.add("ejbContainer");
monNamesList.add("transactionService");
monNamesList.add("orb");
monNamesList.add("connectorService");
monNamesList.add("jmsService");
monNamesList.add("webServicesContainer");
monNamesList.add("jpa");
monNamesList.add("security");
monNamesList.add("jersey");
monNamesList.add("deployment");
}
final private static List containerDispList = new ArrayList();
final private static List containerNameList = new ArrayList();
@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 = ((BigDecimal) monAttrs.get("lastsampletime")).longValue();
if (lastTime != -1) {
last = df.format(new Date(lastTime));
}
Long startTime = ((BigDecimal) monAttrs.get("starttime")).longValue();
if (startTime != -1) {
start = df.format(new Date(startTime));
}
if ("List".equals(unit)){
ArrayList