Package com.sun.enterprise.config.serverbeans

Examples of com.sun.enterprise.config.serverbeans.ConvergedLbConfig


        if (clbConfigs == null) {
            String msg = _strMgr.getString("NoLbConfigsElement");
            throw new MBeanException(new ConfigException(msg));
        }

        ConvergedLbConfig clbConfig = clbConfigs.getConvergedLbConfigByName(configName);

        if (clbConfig == null) {
            // Nothing to be deleted
            String msg = _strMgr.getString("InvalidLbConfigName", configName);
            throw new MBeanException(new ConfigException(msg));
        }

        if (((clbConfig.getServerRef() == null) ||
                (clbConfig.getServerRef().length == 0)) &&
                ((clbConfig.getConvergedLbClusterRef() == null) ||
                (clbConfig.getConvergedLbClusterRef().length == 0))) {
            clbConfigs.removeConvergedLbConfig(clbConfig);
            _logger.log(Level.INFO,
                _sMgr.getString("sip.clbadmin.LbConfigDeleted", configName));
        } else {
            String msg = _strMgr.getString("LbConfigNotEmpty", configName);
View Full Code Here


            }
            else {
                // check if given clb config exists and
                // if clbconfig has dcr file already set
                // copy the dcr file to corresponding cluster config directory
                ConvergedLbConfig clbConfig = getConvergedLbConfig(clbConfigName);
                copyDcrFile(clbConfig, targetName);
            }
                   
            // we have to create it
            clb = new ConvergedLoadBalancer();
View Full Code Here

                    throw new MBeanException(new ConfigException(msg));
                }
            }

            ConvergedLbConfigs clbConfigs = getConvergedLbConfigs();
            ConvergedLbConfig clbConfig = clbConfigs.getConvergedLbConfigByName(clbName + "_CLB_CONFIG");
            if (clbConfig != null) {
                _logger.log(Level.FINE, "Before deleting CLB Checking if it contains cluster references");
                ConvergedLbClusterRef[] clbClusterRefs = clbConfig.getConvergedLbClusterRef();
                if (clbClusterRefs.length != 0) {
                    String msg = _strMgr.getString("ClbContainsClusterRefs");
                    throw new MBeanException(new ConfigException(msg));
                }
                clbConfigs.removeConvergedLbConfig(clbConfig);
View Full Code Here

        return null;
    }

    private void addServerToConvergedLbConfig(String configName,
        String serverName) throws MBeanException {
        ConvergedLbConfig clbConfig = getConvergedLbConfig(configName);

        // Check if there is already cluster-ref
        ConvergedLbClusterRef[] clbRefs = clbConfig.getConvergedLbClusterRef();
        if (clbRefs != null && clbRefs.length > 0) {
            String msg = _strMgr.getString("ClusterServerRefCannotCoExist");
            throw new MBeanException(new ConfigException(msg));
        }
       
        // check if there is already server-ref
        ServerRef[] sRefs = clbConfig.getServerRef();
        if (sRefs != null && sRefs.length > 0) {
            String msg = _strMgr.getString("ClusterServerRefCannotCoExist", serverName);
            throw new MBeanException(new ConfigException(msg));
        }

        try {
            ConfigContext ctx = AdminService.getAdminService().getAdminContext()
                                            .getAdminConfigContext();

            if (!ServerHelper.isServerStandAlone(ctx, serverName)) {
                String msg = _strMgr.getString("NotStandAloneInstance",
                        serverName);
                throw new MBeanException(new ConfigException(msg));
            }

            ServerRef sRef = new ServerRef();
            sRef.setRef(serverName);
            clbConfig.addServerRef(sRef);
        } catch (ConfigException ce) {
            throw new MBeanException(ce);
        }
    }
View Full Code Here

        }
    }

    private void addClusterToConvergedLbConfig(String configName,
        String clusterName, boolean selfloadbalance) throws MBeanException {
        ConvergedLbConfig clbConfig = getConvergedLbConfig(configName);

        // check if there is already server-ref
        ServerRef[] sRefs = clbConfig.getServerRef();
        if (sRefs != null && sRefs.length > 0) {
            String msg = _strMgr.getString("ClusterServerRefCannotCoExist");
            throw new MBeanException(new ConfigException(msg));
        }
       
        ConvergedLbClusterRef[] clbRefs = clbConfig.getConvergedLbClusterRef();
        if (clbRefs != null) {
            for (int i=0; i < clbRefs.length; i++) {
                // check if there is already cluster-ref with same name
                if (clbRefs[i].getRef().equals(clusterName)) {
                    String msg = _strMgr.getString("CLBRefExist", clusterName);
                    throw new MBeanException(new ConfigException(msg));
                } else {
                    // check if there is already cluster-ref with selfloadbalance as true
                    boolean selfLb = clbRefs[i].isSelfLoadbalance();
                    if (selfLb) {
                        String msg = _strMgr.getString("CLBConfigAsSelfLB");
                        throw new MBeanException(new ConfigException(msg));
                    } else if (!selfLb && selfloadbalance) { // check if there is already cluster-ref with self loadbalance as false and current selfloadbalance is true
                        String msg = _strMgr.getString("CLBConfigAsSelfLBMoreRef");
                        throw new MBeanException(new ConfigException(msg));
                    }
                }
            }
        }
           
        ConvergedLbClusterRef clbRef = new ConvergedLbClusterRef();
        clbRef.setRef(clusterName);
        clbRef.setSelfLoadbalance(selfloadbalance);

        try {
            clbConfig.addConvergedLbClusterRef(clbRef);
        } catch (ConfigException ce) {
            throw new MBeanException(ce);
        }
    }
View Full Code Here

                String msg = _strMgr.getString("InvalidTarget", target);
                throw new MBeanException(new RuntimeException(msg));
            }

            ApplicationRef[] appRefs = null;
            ConvergedLbConfig clbConfig = getConvergedLbConfig(clbConfigName);

            if (ClusterHelper.isACluster(ctx, target)) {
                Cluster c = ClusterHelper.getClusterByName(ctx, target);

                if (c == null) {
                    String msg = _strMgr.getString("ClusterNotDefined", target);
                    throw new MBeanException(new ConfigException(msg));
                }

                appRefs = c.getApplicationRef();

                ServerRef[] sRefs = c.getServerRef();

                for (int i = 0; i < sRefs.length; i++)
                    sRefs[i].setLbEnabled(lbEnableInstances);
            } else {
                Server s = ServerHelper.getServerByName(ctx, target);

                if (s == null) {
                    String msg = _strMgr.getString("InstanceNotFound", target);
                    throw new MBeanException(new ConfigException(msg));
                }

                appRefs = s.getApplicationRef();

                ServerRef sRef = clbConfig.getServerRefByRef(target);
                sRef.setLbEnabled(lbEnableInstances);
            }
        } catch (ConfigException ce) {
            throw new MBeanException(ce);
        }
View Full Code Here

        }
    }

    private void deleteServerFromConvergedLbConfig(String configName, Boolean force,
        String serverName) throws MBeanException {
        ConvergedLbConfig clbConfig = getConvergedLbConfig(configName);

        ServerRef sRef = clbConfig.getServerRefByRef(serverName);

        if (sRef == null) {
            // does not exist, just return from here
            _logger.log(Level.FINEST,
                " server " + serverName +
                " does not exist in any cluster in the domain");

            String msg = _strMgr.getString("ServerNotDefined", serverName);
            throw new MBeanException(new RuntimeException(msg));
        }

        if (sRef.isLbEnabled() && (!force)) {
            String msg = _strMgr.getString("ServerNeedsToBeDisabled", serverName);
            throw new MBeanException(new ConfigException(msg));
        }

        // check if its applications are LB disabled.
        Server s = null;

        try {
            ConfigContext ctx = AdminService.getAdminService().getAdminContext()
                                            .getAdminConfigContext();
            s = ServerHelper.getServerByName(ctx, sRef.getRef());
        } catch (ConfigException ce) {
            throw new MBeanException(ce);
        }

        if (s == null) {
            String msg = _strMgr.getString("ServerNotDefined", serverName);
            throw new MBeanException(new ConfigException(msg));
        }

        ApplicationRef[] appRef = s.getApplicationRef();

        if (appRef == null) {
            String msg = _strMgr.getString("AppRefsNotDefined", serverName);
            throw new MBeanException(new ConfigException(msg));
        }

        int i = 0;

        for (i = 0; i < appRef.length; i++) {
            if (appRef[i].isLbEnabled()) {
                break;
            }
        }

        if (i < appRef.length) {
            String msg = _strMgr.getString("AppsNotDisabled");
            throw new MBeanException(new ConfigException(msg));
        }

        clbConfig.removeServerRef(sRef);
    }
View Full Code Here

        clbConfig.removeServerRef(sRef);
    }

    private void deleteClusterFromConvergedLbConfig(String configName, Boolean force,
        String clusterName) throws MBeanException {
        ConvergedLbConfig clbConfig = getConvergedLbConfig(configName);

        ConvergedLbClusterRef clbcRef = clbConfig.getConvergedLbClusterRefByRef(clusterName);

        if (clbcRef == null) {
            String msg = _strMgr.getString("ClusterNotDefinedInClbConfig", clusterName);
            throw new MBeanException(new ConfigException(msg));
        }

        Cluster c = null;

        try {
            ConfigContext ctx = AdminService.getAdminService().getAdminContext()
                                            .getAdminConfigContext();
            c = ClusterHelper.getClusterByName(ctx, clusterName);
        } catch (ConfigException ce) {
            throw new MBeanException(ce);
        }

        if (c == null) {
            String msg = _strMgr.getString("ClusterNotDefined", clusterName);
            throw new MBeanException(new ConfigException(msg));
        }

        ServerRef[] sRefs = c.getServerRef();

        for (int i = 0; i < sRefs.length; i++) {
            if (sRefs[i].isLbEnabled() && (!force)) {
                String msg = _strMgr.getString("ServerNeedsToBeDisabled",
                        clusterName);
                throw new MBeanException(new ConfigException(msg));
            }
        }

        clbConfig.removeConvergedLbClusterRef(clbcRef);
    }
View Full Code Here

        String dcrFile = file.getName();
                   
        // check if dcr file is already set
        String dcrNewFile = null;
        ConvergedLbConfigs clbConfigs = null;
        ConvergedLbConfig clbConfig = null;
        try {
            clbConfigs = getConvergedLbConfigs();
            if (clbConfigs == null) {
                String msg = _strMgr.getString("NoLbConfigsElement");
                throw new MBeanException(new ConfigException(msg));
            }

            clbConfig = clbConfigs.getConvergedLbConfigByName(clbConfigName);
            if (clbConfig == null) {
                String msg = _strMgr.getString("InvalidLbConfigName", clbConfigName);
                throw new MBeanException(new ConfigException(msg));
            }

            MBeanServer mbs = AdminService.getAdminService().getAdminContext().getMBeanServer();
            String[] types = new String[] {(new String[]{}).getClass().getName()};
            // Get the value of config-file
            Object[] returnValues = (Object[])mbs.invoke(
                                        new ObjectName("com.sun.appserv:name=dotted-name-get-set,type=dotted-name-support"),
                                        "dottedNameGet",
                                        new Object[] {new String[] {"domain.converged-lb-configs." + clbConfigName + ".converged-lb-policy.dcr-file"}},
                                        types);
            Attribute attr = (Attribute) returnValues[0];
            String dcrOldFile = (String) attr.getValue();
            dcrNewFile = dcrFile;
            if (dcrOldFile == null || (dcrOldFile != null && dcrOldFile.equals("")))
                dcrOldFile = dcrFile;
           
            String dcrOldFileWOVersion = null;
            if (dcrOldFile.lastIndexOf(".v") != -1) {
                int versionNumPos = dcrOldFile.lastIndexOf(".v");
                dcrOldFileWOVersion = dcrOldFile.substring(0, versionNumPos);
            } else
                dcrOldFileWOVersion = dcrOldFile;
           
            String iRoot = System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY);
            String sDcrOldFile = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + dcrFile;
            File oldFileName = new File(sDcrOldFile);
            Object[] configsUsingCLBConfig = getConfigsUsingCLBConfig(clbConfigName);
            // If clb config is not used by any CLB,
            // do not copy the dcr file from the config directory to cluster config
            if (isClbCfgUsed(clbConfigName)) {
                if (dcrOldFileWOVersion.equals(dcrFile)) {
                    // Following gets executed when the uploaded dcr file name is same as previous dcr file name
                    dcrNewFile = ClbAdminEventHelper.getConfigFileNewValue(dcrOldFile);
                    try {
                        if (configsUsingCLBConfig != null) {
                            for (int i=0; i < configsUsingCLBConfig.length; i++) {
                                // Following copies the dcr file from config directory to config/<cluster-specific-config> directory
                                String sDcrNewFile = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + configsUsingCLBConfig[i]
                                                                                                                            + File.separator + dcrNewFile;
                                File newFileName = new File(sDcrNewFile);
                                FileUtils.copy(oldFileName, newFileName);

                                // Following deletes the dcr file under config/<cluster-specific-config> directory
                                // Do not delete the old dcr files if debug is set as true
                                if (!ClbAdminEventHelper.isClbDebug()) {
                                    String tmp = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + configsUsingCLBConfig[i]
                                                                                                                            + File.separator + dcrOldFile;
                                    File tmpFile = new File(tmp);
                                    if (tmpFile.exists())
                                        tmpFile.delete();
                                }
                            }
                        }
                    } catch (Exception e) {
                        throw new MBeanException(e);
                    }

                } else {
                    // Following gets executed when the uploaded dcr file name is different from previous dcr file name
                    if (configsUsingCLBConfig != null) {
                        for (int i=0; i < configsUsingCLBConfig.length; i++) {
                            String sDcrNewFile = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + configsUsingCLBConfig[i]
                                                                                                                        + File.separator + dcrNewFile;
                            File newFileName = new File(sDcrNewFile);
                            FileUtils.copy(oldFileName, newFileName);

                            // Following deletes the dcr file under config/<cluster-specific-config> directory
                            // Do not delete the old dcr files if debug is set as true
                            if (!ClbAdminEventHelper.isClbDebug()) {
                                String tmp = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + configsUsingCLBConfig[i]
                                                                                                                        + File.separator + dcrOldFile;
                                File tmpFile = new File(tmp);
                                if (tmpFile.exists())
                                    tmpFile.delete();
                            }
                        }
                    }
                }
                // Following deletes the dcr file under the domains/domain/config directory
                // sDcrOldFile = iRoot + File.separator + PEFileLayout.CONFIG_DIR + File.separator + dcrFile;
                // File tmpFile = new File(sDcrOldFile);
                if (oldFileName.exists())
                    oldFileName.delete();
            }
        } catch (Exception e) {
            throw new MBeanException(e);
        }

        ConvergedLbPolicy clbPolicy = clbConfig.getConvergedLbPolicy();
        clbPolicy.setDcrFile(dcrNewFile);
    }
View Full Code Here

TOP

Related Classes of com.sun.enterprise.config.serverbeans.ConvergedLbConfig

Copyright © 2018 www.massapicom. 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.