Search in sources :

Example 1 with Cluster

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

the class CreateHTTPLBRefCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    report = context.getActionReport();
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    boolean isCluster = (target != null) ? tgt.isCluster(target) : false;
    if (config != null && lbname != null) {
        String msg = localStrings.getLocalString("EitherConfigOrLBName", "Either LB name or LB config name, not both");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    if (config == null && lbname == null) {
        String msg = localStrings.getLocalString("SpecifyConfigOrLBName", "Please specify either LB name or LB config name.");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    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 (config != null) {
        if (lbconfigs.getLbConfig(config) == null) {
            String msg = localStrings.getLocalString("LbConfigDoesNotExist", "Specified LB config {0} does not exist", config);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    } else if (lbname != null) {
        LoadBalancers lbs = domain.getExtensionByType(LoadBalancers.class);
        if (lbs == null) {
            String msg = localStrings.getLocalString("NoLoadBalancersElement", "No Load balancers defined.");
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        LoadBalancer lb = lbs.getLoadBalancer(lbname);
        if (lb == null) {
            String msg = localStrings.getLocalString("LoadBalancerNotDefined", "Load balancer [{0}] not found.", lbname);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        config = lb.getLbConfigName();
    }
    if ((lbpolicy != null) || (lbpolicymodule != null)) {
        if (!isCluster) {
            String msg = localStrings.getLocalString("NotCluster", "{0} not a cluster", target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    }
    Cluster c = null;
    Server s = null;
    if (isCluster) {
        c = domain.getClusterNamed(target);
        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;
        }
    } else {
        s = domain.getServerNamed(target);
        if (s == null) {
            String msg = localStrings.getLocalString("ServerNotDefined", "Server {0} cannot be used as target", target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    }
    // create lb ref
    createLBRef(lbconfigs, target, config);
    if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
        return;
    }
    if (healthcheckerurl != null) {
        try {
            final CreateHTTPHealthCheckerCommand command = (CreateHTTPHealthCheckerCommand) runner.getCommand("create-http-health-checker", report, context.getLogger());
            command.url = healthcheckerurl;
            command.interval = healthcheckerinterval;
            command.timeout = healthcheckertimeout;
            command.config = config;
            command.target = target;
            command.execute(context);
            checkCommandStatus(context);
        } catch (CommandException e) {
            String msg = e.getLocalizedMessage();
            logger.warning(msg);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    }
    if (Boolean.parseBoolean(lbenableallinstances)) {
        try {
            final EnableHTTPLBServerCommand command = (EnableHTTPLBServerCommand) runner.getCommand("enable-http-lb-server", report, context.getLogger());
            command.target = target;
            command.execute(context);
            checkCommandStatus(context);
        } catch (CommandException e) {
            String msg = e.getLocalizedMessage();
            logger.warning(msg);
        // report.setActionExitCode(ExitCode.FAILURE);
        // report.setMessage(msg);
        // return;
        }
    }
    if (Boolean.parseBoolean(lbenableallapplications)) {
        List<ApplicationRef> appRefs = domain.getApplicationRefsInTarget(target);
        if ((appRefs.size() > 0) && Boolean.parseBoolean(lbenableallapplications)) {
            for (ApplicationRef ref : appRefs) {
                // enable only user applications
                if (isUserApp(ref.getRef())) {
                    enableApp(context, ref.getRef());
                }
            }
        }
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) LbConfigs(org.glassfish.loadbalancer.config.LbConfigs) LoadBalancers(org.glassfish.loadbalancer.config.LoadBalancers) LoadBalancer(org.glassfish.loadbalancer.config.LoadBalancer) Cluster(com.sun.enterprise.config.serverbeans.Cluster) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 2 with Cluster

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

the class LBCommandsBase method updateLBForCluster.

void updateLBForCluster(ActionReport report, String clusterName, String value, String timeout) {
    Cluster c = domain.getClusterNamed(clusterName);
    if (c == null) {
        report.setMessage("Cluster not defined");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    for (ServerRef sRef : c.getServerRef()) {
        try {
            updateLbEnabled(sRef, value, timeout);
        } catch (TransactionFailure ex) {
            report.setMessage("Failed to update lb-enabled");
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
}
Also used : Cluster(com.sun.enterprise.config.serverbeans.Cluster) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 3 with Cluster

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

the class LBCommandsBase method getServerRefFromCluster.

ServerRef getServerRefFromCluster(ActionReport report, String target) {
    // check if this server is part of cluster
    Cluster c = domain.getClusterForInstance(target);
    if (c == null) {
        report.setMessage("ServerNotDefined");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return null;
    } else {
        return c.getServerRefByRef(target);
    }
}
Also used : Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Example 4 with Cluster

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

the class LoadbalancerReaderImpl method getClustersData.

public ClusterReader[] getClustersData() throws LbReaderException {
    ClusterReader[] cls = new ClusterReader[_clusters.size()];
    Iterator<String> iter = _clusters.iterator();
    int i = 0;
    boolean isFirstServer = false;
    while (iter.hasNext()) {
        String name = iter.next();
        boolean isServer = _domain.isServer(name);
        if (i == 0) {
            isFirstServer = isServer;
        } else {
            // Mix of standalone instances and clusters is not allowed
            if (isFirstServer ^ isServer) {
                String msg = LbLogUtil.getStringManager().getString("MixofServerAndClusterNotSupported");
                throw new LbReaderException(msg);
            }
        }
        if (isServer) {
            Server server = _domain.getServerNamed(name);
            // An instance within cluster is not allowed
            if (server.getCluster() != null) {
                String msg = LbLogUtil.getStringManager().getString("ServerPartofClusterNotSupported", name);
                throw new LbReaderException(msg);
            }
            cls[i++] = new StandAloneClusterReaderImpl(_domain, _appRegistry, server);
        } else {
            Cluster cluster = _domain.getClusterNamed(name);
            if (cluster == null) {
                String msg = LbLogUtil.getStringManager().getString("ClusterorInstanceNotFound", name);
                throw new LbReaderException(msg);
            }
            cls[i++] = new ClusterReaderImpl(_domain, _appRegistry, cluster);
        }
    }
    return cls;
}
Also used : ClusterReader(org.glassfish.loadbalancer.admin.cli.reader.api.ClusterReader) Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException)

Example 5 with Cluster

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

the class JMSDestination method getTypeForTarget.

protected CommandTarget getTypeForTarget(String target) {
    Domain domain = Globals.get(Domain.class);
    Config config = domain.getConfigNamed(target);
    if (config != null)
        return CommandTarget.CONFIG;
    Server targetServer = domain.getServerNamed(target);
    if (targetServer != null) {
        // return CommandTarget.CLUSTERED_INSTANCE;
        if (targetServer.isDas())
            return CommandTarget.DAS;
        else
            return CommandTarget.STANDALONE_INSTANCE;
    }
    // end if (targetServer!=null)
    Cluster cluster = domain.getClusterNamed(target);
    if (cluster != null) {
        return CommandTarget.CLUSTER;
    }
    return CommandTarget.DAS;
}
Also used : Cluster(com.sun.enterprise.config.serverbeans.Cluster)

Aggregations

Cluster (com.sun.enterprise.config.serverbeans.Cluster)45 Server (com.sun.enterprise.config.serverbeans.Server)26 ActionReport (org.glassfish.api.ActionReport)12 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 Domain (com.sun.enterprise.config.serverbeans.Domain)8 HashMap (java.util.HashMap)8 Config (com.sun.enterprise.config.serverbeans.Config)6 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ServerRef (com.sun.enterprise.config.serverbeans.ServerRef)5 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)5 PropertyVetoException (java.beans.PropertyVetoException)5 Test (org.junit.Test)5 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)4 Logger (java.util.logging.Logger)4 ConfigBean (org.jvnet.hk2.config.ConfigBean)4 ConfigSupport (org.jvnet.hk2.config.ConfigSupport)4 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)3 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)3