Package org.jvnet.glassfish.comms.admin.gui.extensions.handlers

Source Code of org.jvnet.glassfish.comms.admin.gui.extensions.handlers.CLBClusterHandlers

/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. 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.html
* or glassfish/bootstrap/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 glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code.  If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [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.
*/

/*
* CLBClusterHandlers.java
*
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package org.jvnet.glassfish.comms.admin.gui.extensions.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.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

import com.sun.enterprise.tools.admingui.util.AMXUtil;
import com.sun.enterprise.tools.admingui.util.GuiUtil;

import com.sun.enterprise.tools.admingui.handlers.ClusterHandlers;

import com.sun.enterprise.admin.server.core.AdminService;
import com.sun.enterprise.config.ConfigContext;
import com.sun.enterprise.config.ConfigException;
import com.sun.enterprise.config.serverbeans.ConvergedLbClusterRef;
import com.sun.enterprise.config.serverbeans.ConvergedLbConfig;
import com.sun.enterprise.config.serverbeans.ConvergedLbConfigs;
import com.sun.enterprise.config.serverbeans.Domain;

import com.sun.appserv.management.config.ClusterConfig;
import com.sun.appserv.management.config.ServerRefConfig;
import com.sun.appserv.management.config.ClusteredServerConfig;


/**
*
* @author Administrator
*/
public class CLBClusterHandlers extends ClusterHandlers{
  
   
    /**
     *  <p> This handler returns the list of Clustered Instances for populating the table.
     *  @param  context  The HandlerContext.
     */
    @Handler(id="getListOfClusteredInstances",
        input={
            @HandlerInput(name="ClusterName", type=String.class, required=true)},   
        output={
            @HandlerOutput(name="result", type=java.util.List.class),
            @HandlerOutput(name="hasLB", type=Boolean.class)}
     )
     public static void getListOfClusteredInstances(HandlerContext handlerCtx){
        String clusterName = (String) handlerCtx.getInputValue("ClusterName");
        try{
            ClusterConfig clusterConfig = AMXUtil.getDomainConfig().getClusterConfigMap().get(clusterName);
            Map<String,ClusteredServerConfig> serverMap = AMXUtil.getDomainConfig().getClusterConfigMap().get(clusterName).getClusteredServerConfigMap();
            List result = new ArrayList();
            if(serverMap != null) {
                for(String key : serverMap.keySet()){
                    HashMap oneRow = new HashMap();
                    String serverName = key;
                    String config = serverMap.get(key).getReferencedConfigName();
                    String node = serverMap.get(key).getReferencedNodeAgentName();
                    String weight = serverMap.get(key).getLBWeight();
                    String state = AMXUtil.getStatusForDisplay(
                            AMXUtil.getJ2EEDomain().getJ2EEServerMap().get(serverName), true);
                   
                    oneRow.put("name", serverName);
                    oneRow.put("selected", false);
                    oneRow.put("config", (config == null) ? " ": config);
                    oneRow.put("node", (node == null) ? " ": node);
                    oneRow.put("weight", (weight == null) ? " ": weight);
                    oneRow.put("status", (state == null) ? " ": state);
                   
                    ServerRefConfig serverRef = clusterConfig.getServerRefConfigMap().get(key);
                    int timeout = serverRef.getDisableTimeoutInMinutes();
                    oneRow.put("timeout", ""+timeout);
                    oneRow.put("lbStatus", ""+serverRef.getLBEnabled());
                   
                    result.add(oneRow);
                }
            }
           
            boolean hasLB =  isClusterCLB(clusterName);
            handlerCtx.setOutputValue("hasLB", hasLB);
            handlerCtx.setOutputValue("result", result);
        }catch(Exception ex){
            GuiUtil.handleException(handlerCtx, ex);
        }
    }

    private static boolean isClusterCLB(String clusterName) {
        boolean matchFound = false;
       
        try {
            ConfigContext adminConfigContext =
                    AdminService.getAdminService().getAdminContext().getAdminConfigContext();
            Domain domain = (Domain) adminConfigContext.getRootConfigBean();
            ConvergedLbConfigs clbConfigs = domain.getConvergedLbConfigs();
            // Null in case of a DAS or developer profile instance.Hence no CLB
            // frontending  this cluster.
            if (clbConfigs == null) {
                return false;
            }
            ConvergedLbConfig[] clbConfigArray = clbConfigs.getConvergedLbConfig();
            //get all converged lb refs amd find whether cluster supports CLB or not.           
            for (int i = 0; i < clbConfigArray.length && !matchFound; i++) {
                ConvergedLbClusterRef[] clusterRefs =
                        clbConfigArray[i].getConvergedLbClusterRef();
                for (int j = 0; j < clusterRefs.length; j++) {
                    if (clusterRefs[j].getRef().equals(clusterName)) {
                        matchFound = true;
                        break;
                    }
                }
            }
        } catch (ConfigException ex) {
            throw new RuntimeException(ex);
        }
        return matchFound;
    }
}
TOP

Related Classes of org.jvnet.glassfish.comms.admin.gui.extensions.handlers.CLBClusterHandlers

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.