Search in sources :

Example 11 with ServerRef

use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.

the class DeleteHTTPLBRefCommand method deleteClusterFromLBConfig.

private void deleteClusterFromLBConfig(LbConfigs lbconfigs, String configName, String clusterName) {
    LbConfig lbConfig = lbconfigs.getLbConfig(configName);
    ClusterRef cRef = lbConfig.getRefByRef(ClusterRef.class, clusterName);
    if (cRef == null) {
        // does not exist, just return from here
        String msg = localStrings.getLocalString("ClusterNotDefined", "Cluster {0} cannot be used as target", target);
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest("Cluster " + clusterName + " does not exist.");
        }
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    if (!Boolean.parseBoolean(force)) {
        Cluster c = domain.getClusterNamed(clusterName);
        if (c == null) {
            String msg = localStrings.getLocalString("ClusterNotDefined", "Cluster {0} cannot be used as target", target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        List<ServerRef> sRefs = c.getServerRef();
        boolean refLbEnabled = false;
        for (ServerRef ref : sRefs) {
            if (Boolean.parseBoolean(ref.getLbEnabled())) {
                refLbEnabled = true;
            }
        }
        if (refLbEnabled) {
            String msg = localStrings.getLocalString("ServerNeedsToBeDisabled", "Server [{0}] needs to be disabled before it can be removed from the load balancer.", target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    }
    removeClusterRef(lbConfig, cRef);
}
Also used : LbConfig(org.glassfish.loadbalancer.config.LbConfig) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 12 with ServerRef

use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.

the class EnableHTTPLBServerCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    LbConfigs lbconfigs = domain.getExtensionByType(LbConfigs.class);
    if (lbconfigs == null) {
        String msg = localStrings.getLocalString("NoLbConfigsElement", "Empty lb-configs");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    if (tgt.isCluster(target)) {
        // enable all servers in cluster
        updateLBForCluster(report, target, "true", null);
    } else {
        boolean foundTarget = false;
        List<LbConfig> lbConfigs = lbconfigs.getLbConfig();
        for (LbConfig lc : lbConfigs) {
            // ServerRef  sRef = lc.getServerRefByRef(target);
            ServerRef sRef = lc.getRefByRef(ServerRef.class, target);
            if (sRef == null) {
                // log a warning and continue search
                logger.warning(localStrings.getLocalString("InvalidInstance", "Server {0} does not exist in {1}", target, lc.getName()));
            } else {
                boolean enabled = sRef.getLbEnabled().equals("true");
                if (enabled == true) {
                    String msg = localStrings.getLocalString("ServerEnabled", "Server [{0}] is already enabled.", sRef.getRef());
                    report.setMessage(msg);
                    return;
                }
                try {
                    updateLbEnabled(sRef, "true", null);
                } catch (TransactionFailure ex) {
                    String msg = localStrings.getLocalString("FailedToUpdateAttr", "Failed to update lb-enabled attribute for {0}", target);
                    report.setMessage(msg);
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setFailureCause(ex);
                    return;
                }
                foundTarget = true;
            }
        }
        // did not find server target
        if (!foundTarget) {
            ServerRef sRef = getServerRefFromCluster(report, target);
            if (sRef == null) {
                String msg = localStrings.getLocalString("InvalidServer", "Server {0} does not exist", target);
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                report.setMessage(msg);
                return;
            } else {
                boolean enabled = sRef.getLbEnabled().equals("true");
                if (enabled == true) {
                    String msg = localStrings.getLocalString("ServerEnabled", "Server [{0}] is already enabled.", sRef.getRef());
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setMessage(msg);
                    return;
                }
                try {
                    updateLbEnabled(sRef, "true", null);
                } catch (TransactionFailure ex) {
                    String msg = localStrings.getLocalString("FailedToUpdateAttr", "Failed to update lb-enabled attribute for {0}", target);
                    report.setMessage(msg);
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                    report.setFailureCause(ex);
                    return;
                }
            }
        }
    }
}
Also used : LbConfigs(org.glassfish.loadbalancer.config.LbConfigs) LbConfig(org.glassfish.loadbalancer.config.LbConfig) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 13 with ServerRef

use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.

the class ListLBConfigsCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    report = context.getActionReport();
    ActionReport.MessagePart part = report.getTopMessagePart();
    boolean isCluster = tgt.isCluster(list_target);
    LbConfigs lbconfigs = domain.getExtensionByType(LbConfigs.class);
    if (lbconfigs == null) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine(localStrings.getLocalString("http_lb_admin.NoLbConfigs", "No lb configs"));
        }
        return;
    }
    List<LbConfig> lbconfigsList = lbconfigs.getLbConfig();
    if (lbconfigsList.size() == 0) {
        logger.fine(localStrings.getLocalString("http_lb_admin.NoLbConfigs", "No lb configs"));
        return;
    }
    if (list_target == null) {
        for (LbConfig lbc : lbconfigsList) {
            ActionReport.MessagePart childPart = part.addChild();
            childPart.setMessage(lbc.getName());
        }
    } else {
        // target is a cluster
        if (isCluster) {
            for (LbConfig lbc : lbconfigsList) {
                List<ClusterRef> refs = lbc.getRefs(ClusterRef.class);
                for (ClusterRef cRef : refs) {
                    if (cRef.getRef().equals(list_target)) {
                        ActionReport.MessagePart childPart = part.addChild();
                        childPart.setMessage(lbc.getName());
                    }
                }
            }
        // target is a server
        } else if (domain.isServer(list_target)) {
            for (LbConfig lbc : lbconfigsList) {
                List<ServerRef> refs = lbc.getRefs(ServerRef.class);
                for (ServerRef sRef : refs) {
                    if (sRef.getRef().equals(list_target)) {
                        ActionReport.MessagePart childPart = part.addChild();
                        childPart.setMessage(lbc.getName());
                    }
                }
            }
        } else {
            // target is a lb config
            LbConfig lbConfig = lbconfigs.getLbConfig(list_target);
            if (lbConfig != null) {
                List<ClusterRef> cRefs = lbConfig.getRefs(ClusterRef.class);
                for (ClusterRef ref : cRefs) {
                    String s = localStrings.getLocalString("ClusterPrefix", "Cluster:");
                    ActionReport.MessagePart childPart = part.addChild();
                    childPart.setMessage(s + ref.getRef());
                }
                List<ServerRef> sRefs = lbConfig.getRefs(ServerRef.class);
                for (ServerRef ref : sRefs) {
                    String s = localStrings.getLocalString("ServerPrefix", "Server:");
                    ActionReport.MessagePart childPart = part.addChild();
                    childPart.setMessage(s + ref.getRef());
                }
            }
        }
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : LbConfigs(org.glassfish.loadbalancer.config.LbConfigs) LbConfig(org.glassfish.loadbalancer.config.LbConfig) List(java.util.List) ActionReport(org.glassfish.api.ActionReport) ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 14 with ServerRef

use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.

the class LoadbalancerReaderImpl method getClustersDataFromLBConfig.

public ClusterReader[] getClustersDataFromLBConfig() throws LbReaderException {
    List<Ref> serverOrClusters = _lbConfig.getClusterRefOrServerRef();
    ClusterReader[] cls = new ClusterReader[serverOrClusters.size()];
    Iterator<Ref> iter = serverOrClusters.iterator();
    int i = 0;
    while (iter.hasNext()) {
        Ref ref = iter.next();
        if (ref instanceof ServerRef) {
            cls[i++] = new StandAloneClusterReaderImpl(_domain, _appRegistry, (ServerRef) ref);
        } else if (ref instanceof ClusterRef) {
            cls[i++] = new ClusterReaderImpl(_domain, _appRegistry, (ClusterRef) ref);
        } else {
            String msg = LbLogUtil.getStringManager().getString("UnableToDetermineType", ref.getRef());
            throw new LbReaderException(msg);
        }
    }
    return cls;
}
Also used : ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) Ref(com.sun.enterprise.config.serverbeans.Ref) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) ClusterReader(org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)

Example 15 with ServerRef

use of com.sun.enterprise.config.serverbeans.ServerRef in project Payara by payara.

the class CreateHTTPHealthCheckerCommand method matchLbConfigToTarget.

/**
 * Returns an array of LbConfigs that has a reference to the target
 * server or cluster. If there are no references found for the
 * target or the arguments are null, this method returns null.
 *
 * @param  lbConfigs  array of existing LbConfigs in the system
 * @param  target     name of server or cluster
 *
 * @return array of LbConfigs that has a ref to the target server
 */
private List<LbConfig> matchLbConfigToTarget(List<LbConfig> lbConfigs, String target) {
    List<LbConfig> list = null;
    // bad target
    if (target == null) {
        String msg = localStrings.getLocalString("Nulltarget", "Null target");
        logger.warning(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return null;
    }
    // system has lb configs defined
    if (!lbConfigs.isEmpty()) {
        list = new ArrayList<LbConfig>();
        for (int i = 0; i < lbConfigs.size(); i++) {
            // target is a cluster
            if (tgt.isCluster(target)) {
                ClusterRef cRef = lbConfigs.get(i).getRefByRef(ClusterRef.class, target);
                // this lb config has a reference to the target cluster
                if (cRef != null) {
                    list.add(lbConfigs.get(i));
                }
            // target is a server
            } else if (domain.isServer(target)) {
                ServerRef sRef = lbConfigs.get(i).getRefByRef(ServerRef.class, target);
                // this lb config has a reference to the target server
                if (sRef != null) {
                    list.add(lbConfigs.get(i));
                }
            }
        }
    }
    return list;
}
Also used : LbConfig(org.glassfish.loadbalancer.config.LbConfig) ClusterRef(com.sun.enterprise.config.serverbeans.ClusterRef) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Aggregations

ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)16 LbConfig (org.glassfish.loadbalancer.config.LbConfig)7 ClusterRef (com.sun.enterprise.config.serverbeans.ClusterRef)6 Cluster (com.sun.enterprise.config.serverbeans.Cluster)5 Server (com.sun.enterprise.config.serverbeans.Server)4 ActionReport (org.glassfish.api.ActionReport)4 LbConfigs (org.glassfish.loadbalancer.config.LbConfigs)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3 Node (com.sun.enterprise.config.serverbeans.Node)2 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)2 PropertyVetoException (java.beans.PropertyVetoException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Logger (java.util.logging.Logger)2 Test (org.junit.Test)2 ConfigBean (org.jvnet.hk2.config.ConfigBean)2 ConfigSupport (org.jvnet.hk2.config.ConfigSupport)2 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 HealthChecker (com.sun.enterprise.config.serverbeans.HealthChecker)1 Nodes (com.sun.enterprise.config.serverbeans.Nodes)1