Search in sources :

Example 41 with Server

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

the class DeleteHTTPLBRefCommand method deleteServerFromLBConfig.

private void deleteServerFromLBConfig(LbConfigs lbconfigs, String configName, String serverName) {
    LbConfig lbConfig = lbconfigs.getLbConfig(configName);
    ServerRef sRef = lbConfig.getRefByRef(ServerRef.class, serverName);
    if (sRef == null) {
        // does not exist, just return from here
        String msg = localStrings.getLocalString("ServerNotDefined", "Server {0} cannot be used as target", target);
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest("Server " + serverName + " does not exist in any cluster in the domain");
        }
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    if (!Boolean.parseBoolean(force)) {
        if (Boolean.parseBoolean(sRef.getLbEnabled())) {
            String msg = localStrings.getLocalString("ServerNeedsToBeDisabled", "Server [{0}] needs to be disabled before it can be removed from the load balancer.", serverName);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        // check if its applications are LB disabled.
        Server s = domain.getServerNamed(serverName);
        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;
        }
        List<ApplicationRef> appRefs = domain.getApplicationRefsInTarget(target);
        if (appRefs == null) {
            String msg = localStrings.getLocalString("AppRefsNotDefined", "Application refs does not exist in server {0}", target);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
        boolean appLbEnabled = false;
        for (ApplicationRef aRef : appRefs) {
            if (Boolean.parseBoolean(aRef.getLbEnabled())) {
                appLbEnabled = true;
                break;
            }
        }
        if (appLbEnabled) {
            String msg = localStrings.getLocalString("AppsNotDisabled", "All referenced applications must be disabled in LB");
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(msg);
            return;
        }
    }
    removeServerRef(lbConfig, sRef);
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) LbConfig(org.glassfish.loadbalancer.config.LbConfig) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 42 with Server

use of com.sun.enterprise.config.serverbeans.Server 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 43 with Server

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

the class CreateHTTPLBRefCommand method addServerToLBConfig.

private void addServerToLBConfig(final LbConfigs lbconfigs, final String configName, final String serverName) {
    LbConfig lbConfig = lbconfigs.getLbConfig(configName);
    ServerRef sRef = lbConfig.getRefByRef(ServerRef.class, serverName);
    if (sRef != null) {
        String msg = localStrings.getLocalString("LBServerRefExists", "LB config already contains a server-ref for target {0}", target);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    Server server = domain.getServerNamed(serverName);
    boolean isStandAlone = server.getCluster() == null && server.isInstance();
    if (!isStandAlone) {
        String msg = localStrings.getLocalString("NotStandAloneInstance", "[{0}] is not a stand alone instance. Only stand alone instance can be added to a load balancer.", serverName);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<LbConfig>() {

            @Override
            public Object run(LbConfig param) throws PropertyVetoException, TransactionFailure {
                ServerRef ref = param.createChild(ServerRef.class);
                ref.setRef(serverName);
                param.getClusterRefOrServerRef().add(ref);
                return Boolean.TRUE;
            }
        }, lbConfig);
    } catch (TransactionFailure ex) {
        String msg = localStrings.getLocalString("FailedToAddServerRef", "Failed to add server-ref");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        report.setFailureCause(ex);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Server(com.sun.enterprise.config.serverbeans.Server) LbConfig(org.glassfish.loadbalancer.config.LbConfig) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef)

Example 44 with Server

use of com.sun.enterprise.config.serverbeans.Server 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 45 with Server

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

the class J2EEDomainImpl method registerChildren.

@Override
protected void registerChildren() {
    final ObjectNameBuilder builder = getObjectNames();
    final MetadataImpl meta = defaultChildMetadata();
    List<Server> servers = getDomain().getServers().getServer();
    for (Server server : servers) {
        meta.setCorrespondingConfig(ConfigBeanRegistry.getInstance().getObjectNameForProxy(server));
        final DASJ2EEServerImpl impl = new DASJ2EEServerImpl(getObjectName(), meta);
        ObjectName serverObjectName = builder.buildChildObjectName(J2EETypes.J2EE_SERVER, server.getName());
        registerChild(impl, serverObjectName);
    }
// ImplUtil.getLogger().info( "Registered J2EEDomain as " + getObjectName() + " with J2EEServer of " + serverObjectName);
}
Also used : ObjectNameBuilder(org.glassfish.admin.amx.impl.util.ObjectNameBuilder) MBeanServer(javax.management.MBeanServer) Server(com.sun.enterprise.config.serverbeans.Server) ObjectName(javax.management.ObjectName)

Aggregations

Server (com.sun.enterprise.config.serverbeans.Server)101 ActionReport (org.glassfish.api.ActionReport)32 Cluster (com.sun.enterprise.config.serverbeans.Cluster)25 Domain (com.sun.enterprise.config.serverbeans.Domain)15 Node (com.sun.enterprise.config.serverbeans.Node)15 Config (com.sun.enterprise.config.serverbeans.Config)14 Properties (java.util.Properties)14 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 PropertyVetoException (java.beans.PropertyVetoException)11 DeploymentGroup (fish.payara.enterprise.config.serverbeans.DeploymentGroup)9 ParameterMap (org.glassfish.api.admin.ParameterMap)9 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)8 File (java.io.File)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)8 Logger (java.util.logging.Logger)7 Map (java.util.Map)6 ServerContext (org.glassfish.internal.api.ServerContext)6