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.
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* ClusterHandler.java
*
* Created on July 1,2010 9:32 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author anilam
*/
package org.glassfish.admingui.common.handlers;
import com.sun.enterprise.config.serverbeans.Cluster;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.util.SystemPropertyConstants;
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.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.glassfish.admingui.common.util.GuiUtil;
import org.glassfish.admingui.common.util.RestUtil;
import org.glassfish.admingui.common.util.TargetUtil;
import org.glassfish.api.admin.InstanceState;
public class ClusterHandler {
public static final String CLUSTER_RESOURCE_NAME = "org.glassfish.cluster.admingui.Strings";
//The following is defined in v3/cluster/admin/src/main/java/..../cluster/Constants.java
public static final String RUNNING = "RUNNING";
public static final String NOT_RUNNING = "NOT_RUNNING";
public static final String PARTIALLY_RUNNING = "PARTIALLY_RUNNING";
/** Creates a new instance of InstanceHandler */
public ClusterHandler() {
}
/**
* This method takes in a list of instances with status, which is the output of list-instances
* and count the # of instance that is running and non running.
* @param handlerCtx
*/
@Handler(id = "gf.getClusterStatusSummary",
input = {
@HandlerInput(name = "statusMap", type = Map.class, required = true)
},
output = {
@HandlerOutput(name = "numRunning", type = String.class),
@HandlerOutput(name = "numNotRunning", type = String.class),
@HandlerOutput(name = "numRequireRestart", type = String.class),
@HandlerOutput(name = "disableStart", type = Boolean.class),
@HandlerOutput(name = "disableStop", type = Boolean.class),
@HandlerOutput(name = "disableEjb", type = Boolean.class)
})
public static void getClusterStatusSummary(HandlerContext handlerCtx) {
Map statusMap = (Map) handlerCtx.getInputValue("statusMap");
int running=0;
int notRunning=0;
int requireRestart=0;
try{
for (Iterator it=statusMap.values().iterator(); it.hasNext(); ) {
Object value = it.next();
if (value.toString().equals(InstanceState.StateType.RUNNING.getDescription())){
running++;
}else
if (value.toString().equals(InstanceState.StateType.NOT_RUNNING.getDescription())){
notRunning++;
}else
if (value.toString().equals(InstanceState.StateType.RESTART_REQUIRED.getDescription())){
requireRestart++;
}else {
GuiUtil.getLogger().severe("Unknown Status");
}
}
handlerCtx.setOutputValue("disableEjb", (notRunning > 0) ? false :true); //refer to bug#6342445
handlerCtx.setOutputValue("disableStart", (notRunning > 0) ? false :true);
handlerCtx.setOutputValue("disableStop", ( (running+requireRestart) > 0) ? false :true);
handlerCtx.setOutputValue( "numRunning" , (running > 0) ?
GuiUtil.getMessage(CLUSTER_RESOURCE_NAME, "cluster.number.instance.running", new String[]{""+running, GuiUtil.getCommonMessage("status.image.RUNNING")} ) : "");
handlerCtx.setOutputValue( "numNotRunning" , (notRunning > 0) ?
GuiUtil.getMessage(CLUSTER_RESOURCE_NAME, "cluster.number.instance.notRunning", new String[]{""+notRunning , GuiUtil.getCommonMessage("status.image.NOT_RUNNING")}) : "");
handlerCtx.setOutputValue( "numRequireRestart" , (requireRestart > 0) ?
GuiUtil.getMessage(CLUSTER_RESOURCE_NAME, "cluster.number.instance.requireRestart", new String[]{""+requireRestart, GuiUtil.getCommonMessage("status.image.REQUIRES_RESTART")}) : "");
}catch(Exception ex){
handlerCtx.setOutputValue("numRunning", GuiUtil.getMessage(CLUSTER_RESOURCE_NAME, "cluster.status.unknown"));
GuiUtil.getLogger().info(GuiUtil.getCommonMessage("log.error.getClusterStatusSummary") + ex.getLocalizedMessage());
if (GuiUtil.getLogger().isLoggable(Level.FINE)){
ex.printStackTrace();
}
}
}
@Handler(id = "gf.isClusterName",
input = {
@HandlerInput(name = "clusterName", type = String.class, required = true)
},
output = {
@HandlerOutput(name = "exists", type = Boolean.class)
})
public static void isClusterName(HandlerContext handlerCtx) {
if( ! TargetUtil.isCluster((String) handlerCtx.getInputValue("clusterName"))){
GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.NoSuchCluster"));
handlerCtx.setOutputValue("exists", false);
}else{
handlerCtx.setOutputValue("exists", true);
}
}
@Handler(id = "gf.isInstanceName",
input = {
@HandlerInput(name = "instanceName", type = String.class, required = true)
},
output = {
@HandlerOutput(name = "exists", type = Boolean.class)
})
public static void isInstanceName(HandlerContext handlerCtx) {
if( ! TargetUtil.isInstance((String) handlerCtx.getInputValue("instanceName"))){
GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.NoSuchInstance"));
handlerCtx.setOutputValue("exists", false);
}else{
handlerCtx.setOutputValue("exists", true);
}
}
@Handler(id = "gf.isConfigName",
input = {
@HandlerInput(name = "configName", type = String.class, required = true)
},
output = {
@HandlerOutput(name = "exists", type = Boolean.class)
})
public static void isConfigName(HandlerContext handlerCtx) {
String configName = (String) handlerCtx.getInputValue("configName");
List config = TargetUtil.getConfigs();
if(!config.contains(configName)){
GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.NoSuchConfig"));
handlerCtx.setOutputValue("exists", false);
}else{
handlerCtx.setOutputValue("exists", true);
}
}
@Handler(id = "gf.saveInstanceWeight",
input = {
@HandlerInput(name = "rows", type = List.class, required = true)})
public static void saveInstanceWeight(HandlerContext handlerCtx) {
List