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) 2010-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.
*/
/*
* 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.jsftemplating.annotation.Handler;
import com.sun.jsftemplating.annotation.HandlerInput;
import com.sun.jsftemplating.annotation.HandlerOutput;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
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;
import java.net.URLEncoder;
import java.util.*;
import java.util.logging.Level;
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;
int unknown = 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 {
unknown++;
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