Search in sources :

Example 31 with Server

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

the class CLIUtil method chooseConfig.

/**
 * Selects a config of interest from the domain, based on the target. (Eliminates duplicated code formerly in Create,
 * Delete, and ListAuthRealm).
 *
 * @param domain
 * @param target
 * @return
 */
static Config chooseConfig(final Domain domain, final String target) {
    Config config = null;
    Config tmp = null;
    try {
        tmp = domain.getConfigs().getConfigByName(target);
    } catch (Exception ex) {
    }
    if (tmp != null) {
        return tmp;
    }
    Server targetServer = domain.getServerNamed(target);
    if (targetServer != null) {
        config = domain.getConfigNamed(targetServer.getConfigRef());
    }
    com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target);
    if (cluster != null) {
        config = domain.getConfigNamed(cluster.getConfigRef());
    }
    return config;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) MessageSecurityConfig(com.sun.enterprise.config.serverbeans.MessageSecurityConfig)

Example 32 with Server

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

the class LDAPAdminAccessConfigurator method chooseConfig.

private Config chooseConfig() {
    Server s = configBeansUtilities.getServerNamed(ADMIN_SERVER);
    String ac = s.getConfigRef();
    return targetService.getConfig(ac);
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server)

Example 33 with Server

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

the class JmsHandlers method getMBeanServerConnection.

private static MBeanServerConnection getMBeanServerConnection(String target) throws ConnectorRuntimeException, Exception {
    ServiceLocator habitat = GuiUtil.getHabitat();
    Domain domain = habitat.getService(Domain.class);
    Cluster cluster = domain.getClusterNamed(target);
    String configRef = null;
    if (cluster == null) {
        Server server = domain.getServerNamed(target);
        configRef = server.getConfigRef();
    } else {
        configRef = cluster.getConfigRef();
    }
    PhysicalDestinations pd = new PhysicalDestinations();
    MQJMXConnectorInfo mqInfo = pd.getConnectorInfo(target, configRef, habitat, domain);
    return mqInfo.getMQMBeanServerConnection();
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) MBeanServer(javax.management.MBeanServer) Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) Domain(com.sun.enterprise.config.serverbeans.Domain) MQJMXConnectorInfo(org.glassfish.jms.admin.cli.MQJMXConnectorInfo)

Example 34 with Server

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

the class FlushInstancesConnectionPool method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Resources resources = domain.getResources();
    String scope = "";
    if (moduleName != null) {
        if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
            report.setMessage("Modulename is not that of a valid module: " + moduleName);
            report.setActionExitCode(ActionReport.ExitCode.WARNING);
            return;
        }
        Application application = applications.getApplication(applicationName);
        Module module = application.getModule(moduleName);
        resources = module.getResources();
        scope = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX;
    } else if (applicationName != null) {
        if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
            report.setMessage("ApplicationName is not that of a valid module: " + applicationName);
            report.setActionExitCode(ActionReport.ExitCode.WARNING);
            return;
        }
        Application application = applications.getApplication(applicationName);
        resources = application.getResources();
        scope = ConnectorConstants.JAVA_APP_SCOPE_PREFIX;
    }
    if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
        report.setMessage("Connection Pool is not valid");
        report.setActionExitCode(ActionReport.ExitCode.WARNING);
        return;
    }
    List<Future> instanceFlushes = new ArrayList<>();
    for (Server server : domain.getServers().getServer()) {
        instanceFlushes.add(executor.submit(new Runnable() {

            @Override
            public void run() {
                ActionReport subReport = report.addSubActionsReport();
                try {
                    if (!server.isRunning()) {
                        // skip servers that are stopped
                        return;
                    }
                    String host = server.getAdminHost();
                    int port = server.getAdminPort();
                    ParameterMap map = new ParameterMap();
                    map.add("poolName", poolName);
                    if (applicationName != null) {
                        map.add("appname", applicationName);
                    }
                    if (moduleName != null) {
                        map.add("modulename", moduleName);
                    }
                    if (server.isDas()) {
                        CommandRunner runner = habitat.getService(CommandRunner.class);
                        CommandRunner.CommandInvocation invocation = runner.getCommandInvocation("_flush-connection-pool", subReport, context.getSubject());
                        invocation.parameters(map);
                        invocation.execute();
                    } else {
                        RemoteRestAdminCommand rac = new ServerRemoteRestAdminCommand(habitat, "_flush-connection-pool", host, port, false, "admin", null, LOGGER);
                        rac.executeCommand(map);
                        ActionReport result = rac.getActionReport();
                        subReport.setActionExitCode(result.getActionExitCode());
                        subReport.setMessage(result.getMessage());
                    }
                } catch (CommandException ex) {
                    subReport.failure(Logger.getLogger("CONNECTORS-ADMIN"), ex.getLocalizedMessage(), ex);
                    subReport.appendMessage(server.getName());
                    report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                }
            }
        }));
    }
    for (Future future : instanceFlushes) {
        try {
            future.get();
        } catch (InterruptedException | ExecutionException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    }
    if (report.hasFailures()) {
        report.setActionExitCode(ActionReport.ExitCode.WARNING);
    }
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) ArrayList(java.util.ArrayList) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandException(org.glassfish.api.admin.CommandException) ActionReport(org.glassfish.api.ActionReport) RestEndpoint(org.glassfish.api.admin.RestEndpoint) Future(java.util.concurrent.Future) Resources(com.sun.enterprise.config.serverbeans.Resources) Module(com.sun.enterprise.config.serverbeans.Module) ExecutionException(java.util.concurrent.ExecutionException) Application(com.sun.enterprise.config.serverbeans.Application) CommandRunner(org.glassfish.api.admin.CommandRunner) RemoteRestAdminCommand(com.sun.enterprise.admin.remote.RemoteRestAdminCommand) ServerRemoteRestAdminCommand(com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand) ServerRemoteRestAdminCommand(com.sun.enterprise.admin.remote.ServerRemoteRestAdminCommand)

Example 35 with Server

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

the class EjbDeployer method getOwnerId.

private String getOwnerId(String target) {
    // If target is a cluster or deployment group replace it with the instance
    List<Server> instances = Collections.EMPTY_LIST;
    Cluster cluster = domain.getClusterNamed(target);
    if (cluster != null) {
        instances = cluster.getInstances();
    } else {
        DeploymentGroup dg = domain.getDeploymentGroupNamed(target);
        if (dg != null) {
            instances = dg.getInstances();
        } else {
            return target;
        }
    }
    // Try a random instance in a cluster
    int useInstance = random.nextInt(instances.size());
    Server s0 = instances.get(useInstance);
    if (s0.isRunning()) {
        return s0.getName();
    } else {
        // Pick the first running instead
        for (Server s : instances) {
            if (s.isRunning()) {
                return s.getName();
            }
        }
    }
    // cluster
    return s0.getName();
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) DeploymentGroup(fish.payara.enterprise.config.serverbeans.DeploymentGroup)

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