Search in sources :

Example 36 with Config

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

the class TransactionServiceConfigListener method postConstruct.

@Override
public void postConstruct() {
    // Listen to monitoring level changes
    Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
    ts = c.getExtensionByType(TransactionService.class);
    ModuleMonitoringLevels mml = c.getMonitoringService().getModuleMonitoringLevels();
    ((ObservableBean) ConfigSupport.getImpl(mml)).addListener(this);
}
Also used : TransactionService(com.sun.enterprise.transaction.config.TransactionService) ModuleMonitoringLevels(com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels) Config(com.sun.enterprise.config.serverbeans.Config) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Example 37 with Config

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

the class ClusterOperationUtil method replicateCommand.

/**
 * Replicates a given command on the given list of targets, optionally gathering
 * downloaded result payloads from the instance commands into a directory.
 * <p>
 * If intermediateDownloadDir is non-null, then any files returned from
 * the instances in the payload of the HTTP response will be stored in a
 * directory tree like this:
 * <pre>
 * ${intermediateDownloadDir}/
 *     ${instanceA}/
 *         file(s) returned from instance A
 *     ${instanceB}/
 *         file(s) returned from instance B
 *     ...
 * </pre>
 * where ${instanceA}, ${instanceB}, etc. are the names of the instances to
 * which the command was replicated.  This method does no further processing
 * on the downloaded files but leaves that to the calling command.
 */
public static ActionReport.ExitCode replicateCommand(String commandName, FailurePolicy failPolicy, FailurePolicy offlinePolicy, FailurePolicy neverStartedPolicy, List<Server> instancesForReplication, AdminCommandContext context, ParameterMap parameters, ServiceLocator habitat, final File intermediateDownloadDir) {
    ActionReport.ExitCode returnValue = ActionReport.ExitCode.SUCCESS;
    InstanceStateService instanceState = habitat.getService(InstanceStateService.class);
    validateIntermediateDownloadDir(intermediateDownloadDir);
    RemoteInstanceCommandHelper rich = new RemoteInstanceCommandHelper(habitat);
    Map<String, Future<InstanceCommandResult>> futures = new HashMap<>();
    try {
        for (Server svr : instancesForReplication) {
            if (instanceState.getState(svr.getName()) == InstanceState.StateType.NEVER_STARTED) {
                // Do not replicate commands to instances that have never been started.
                // For certain commands, warn about the failure to replicate even if
                // the instance has never been started.
                ActionReport.ExitCode finalResult = FailurePolicy.applyFailurePolicy(neverStartedPolicy, ActionReport.ExitCode.FAILURE);
                if (!finalResult.equals(ActionReport.ExitCode.SUCCESS)) {
                    ActionReport aReport = context.getActionReport().addSubActionsReport();
                    if (finalResult.equals(ActionReport.ExitCode.FAILURE)) {
                        aReport.setMessage(strings.getLocalString("clusterutil.failneverstarted", "FAILURE: Instance {0} has never been started; command {1} was not replicated to that instance", svr.getName(), commandName));
                    } else {
                        aReport.setMessage(strings.getLocalString("clusterutil.warnneverstarted", "WARNING: Instance {0} has never been started; command {1} was not replicated to that instance", svr.getName(), commandName));
                    }
                    aReport.setActionExitCode(finalResult);
                    if (returnValue == ActionReport.ExitCode.SUCCESS)
                        returnValue = finalResult;
                }
                continue;
            }
            Config scfg = svr.getConfig();
            // PAYARA-2162 Restart Required is set erroneously when _get-runtime-info is called
            if (!Boolean.valueOf(scfg.getDynamicReconfigurationEnabled()) && !ALLOWED_COMMANDS.contains(commandName)) {
                // Do not replicate to servers for which dynamic configuration is disabled
                ActionReport aReport = context.getActionReport().addSubActionsReport();
                aReport.setActionExitCode(ActionReport.ExitCode.WARNING);
                aReport.setMessage(strings.getLocalString("clusterutil.dynrecfgdisabled", "WARNING: The command {0} was not replicated to instance {1} because the " + "dynamic-reconfiguration-enabled flag is set to false for config {2}", new Object[] { commandName, svr.getName(), scfg.getName() }));
                instanceState.setState(svr.getName(), InstanceState.StateType.RESTART_REQUIRED, false);
                instanceState.addFailedCommandToInstance(svr.getName(), commandName, parameters);
                returnValue = ActionReport.ExitCode.WARNING;
                continue;
            }
            String host = svr.getAdminHost();
            int port = rich.getAdminPort(svr);
            ActionReport aReport = context.getActionReport().addSubActionsReport();
            InstanceCommandResult aResult = new InstanceCommandResult();
            // InstanceCommandExecutor ice =
            // new InstanceCommandExecutor(habitat, commandName, failPolicy, offlinePolicy,
            // svr, host, port, logger, parameters, aReport, aResult);
            // if (CommandTarget.DAS.isValid(habitat, ice.getServer().getName()))
            // continue;
            // if (intermediateDownloadDir != null) {
            // ice.setFileOutputDirectory(
            // subdirectoryForInstance(intermediateDownloadDir, ice));
            // }
            // Future<InstanceCommandResult> f = instanceState.submitJob(svr, ice, aResult);
            // TODO: Remove this if after only one remote admin call method will be choosen
            Future<InstanceCommandResult> f;
            if (useRest()) {
                InstanceRestCommandExecutor ice = new InstanceRestCommandExecutor(habitat, commandName, failPolicy, offlinePolicy, svr, host, port, logger, parameters, aReport, aResult);
                if (CommandTarget.DAS.isValid(habitat, ice.getServer().getName())) {
                    continue;
                }
                if (intermediateDownloadDir != null) {
                    ice.setFileOutputDirectory(new File(intermediateDownloadDir, ice.getServer().getName()));
                }
                f = instanceState.submitJob(svr, ice, aResult);
            } else {
                logger.log(Level.FINEST, "replicateCommand(): Use traditional way for replication - {0}", commandName);
                InstanceCommandExecutor ice = new InstanceCommandExecutor(habitat, commandName, failPolicy, offlinePolicy, svr, host, port, logger, parameters, aReport, aResult);
                if (CommandTarget.DAS.isValid(habitat, ice.getServer().getName())) {
                    continue;
                }
                if (intermediateDownloadDir != null) {
                    ice.setFileOutputDirectory(new File(intermediateDownloadDir, ice.getServer().getName()));
                }
                f = instanceState.submitJob(svr, ice, aResult);
            }
            if (f == null) {
                logger.severe(AdminLoggerInfo.stateNotFound);
                continue;
            }
            futures.put(svr.getName(), f);
            logger.fine(strings.getLocalString("dynamicreconfiguration.diagnostics.jobsubmitted", "Successfully submitted command {0} for execution at instance {1}", commandName, svr.getName()));
        }
    } catch (Exception ex) {
        ActionReport aReport = context.getActionReport().addSubActionsReport();
        ActionReport.ExitCode finalResult = FailurePolicy.applyFailurePolicy(failPolicy, ActionReport.ExitCode.FAILURE);
        aReport.setActionExitCode(finalResult);
        aReport.setMessage(strings.getLocalString("clusterutil.replicationfailed", "Error during command replication: {0}", ex.getLocalizedMessage()));
        logger.log(Level.SEVERE, AdminLoggerInfo.replicationError, ex.getLocalizedMessage());
        if (returnValue == ActionReport.ExitCode.SUCCESS) {
            returnValue = finalResult;
        }
    }
    boolean gotFirstResponse = false;
    long maxWaitTime = RemoteRestAdminCommand.getReadTimeout();
    long timeBeforeAsadminTimeout = maxWaitTime;
    long waitStart = System.currentTimeMillis();
    for (Map.Entry<String, Future<InstanceCommandResult>> fe : futures.entrySet()) {
        String s = fe.getKey();
        ActionReport.ExitCode finalResult;
        try {
            logger.fine(strings.getLocalString("dynamicreconfiguration.diagnostics.waitingonjob", "Waiting for command {0} to be completed at instance {1}", commandName, s));
            Future<InstanceCommandResult> aFuture = fe.getValue();
            InstanceCommandResult aResult = aFuture.get(maxWaitTime, TimeUnit.MILLISECONDS);
            long elapsedTime = System.currentTimeMillis() - waitStart;
            timeBeforeAsadminTimeout -= elapsedTime;
            if (!gotFirstResponse) {
                maxWaitTime = elapsedTime * 4;
                gotFirstResponse = true;
            }
            if ((maxWaitTime > timeBeforeAsadminTimeout) || (maxWaitTime < 60000)) {
                maxWaitTime = timeBeforeAsadminTimeout;
            }
            ActionReport iReport;
            Server iServer;
            if (useRest()) {
                InstanceRestCommandExecutor ice = (InstanceRestCommandExecutor) aResult.getInstanceCommand();
                iReport = ice.getReport();
                iServer = ice.getServer();
            } else {
                InstanceCommandExecutor ice = (InstanceCommandExecutor) aResult.getInstanceCommand();
                iReport = ice.getReport();
                iServer = ice.getServer();
            }
            if (iReport.getActionExitCode() != ActionReport.ExitCode.FAILURE) {
                completedInstances.add(iServer);
            }
            finalResult = FailurePolicy.applyFailurePolicy(failPolicy, iReport.getActionExitCode());
            if (returnValue == ActionReport.ExitCode.SUCCESS) {
                returnValue = finalResult;
            }
            if (finalResult != ActionReport.ExitCode.SUCCESS) {
                instanceState.setState(s, InstanceState.StateType.RESTART_REQUIRED, false);
                instanceState.addFailedCommandToInstance(s, commandName, parameters);
            }
        } catch (Exception ex) {
            ActionReport aReport = context.getActionReport().addSubActionsReport();
            finalResult = FailurePolicy.applyFailurePolicy(failPolicy, ActionReport.ExitCode.FAILURE);
            if (finalResult == ActionReport.ExitCode.FAILURE) {
                if (ex instanceof TimeoutException)
                    aReport.setMessage(strings.getLocalString("clusterutil.timeoutwhilewaiting", "Timed out while waiting for result from instance {0}", s));
                else
                    aReport.setMessage(strings.getLocalString("clusterutil.exceptionwhilewaiting", "Exception while waiting for result from instance {0} : {1}", s, ex.getLocalizedMessage()));
            }
            aReport.setActionExitCode(finalResult);
            if (returnValue == ActionReport.ExitCode.SUCCESS)
                returnValue = finalResult;
            instanceState.setState(s, InstanceState.StateType.RESTART_REQUIRED, false);
            instanceState.addFailedCommandToInstance(s, commandName, parameters);
        }
    }
    return returnValue;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) TimeoutException(java.util.concurrent.TimeoutException) Future(java.util.concurrent.Future) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException)

Example 38 with Config

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

the class MetroContainer method initializeWsTxRuntime.

/**
 * Initialization of WS-TX runtime configuration
 */
private void initializeWsTxRuntime() {
    final String serverName = serverContext.getInstanceName();
    final Config config = serverContext.getConfigBean().getConfig();
    final WSATRuntimeConfig.TxlogLocationProvider txlogLocationProvider = new WSATRuntimeConfig.TxlogLocationProvider() {

        @Override
        public String getTxLogLocation() {
            return txManager.getTxLogLocation();
        }
    };
    WSATRuntimeConfig.initializer().hostName(getHostName()).httpPort(getHttpPort(false, serverName, config)).httpsPort(getHttpPort(true, serverName, config)).txLogLocation(txlogLocationProvider).done();
    final WSATRuntimeConfig.RecoveryEventListener metroListener = WSATRuntimeConfig.getInstance().new WSATRecoveryEventListener();
    recoveryRegistry.addEventListener(new RecoveryEventListener() {

        @Override
        public void beforeRecovery(boolean delegated, String instance) {
            metroListener.beforeRecovery(delegated, instance);
        }

        @Override
        public void afterRecovery(boolean success, boolean delegated, String instance) {
            metroListener.afterRecovery(success, delegated, instance);
        }
    });
}
Also used : WSATRuntimeConfig(com.sun.xml.ws.tx.dev.WSATRuntimeConfig) Config(com.sun.enterprise.config.serverbeans.Config) WSATRuntimeConfig(com.sun.xml.ws.tx.dev.WSATRuntimeConfig) RecoveryEventListener(com.sun.enterprise.transaction.spi.RecoveryEventListener)

Example 39 with Config

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

the class ContainerExtensionTest method existenceTest.

@Test
public void existenceTest() {
    Config config = habitat.<Domain>getService(Domain.class).getConfigs().getConfig().get(0);
    List<Container> containers = config.getContainers();
    assertTrue(containers.size() == 2);
    RandomContainer container = (RandomContainer) containers.get(0);
    assertEquals("random", container.getName());
    assertEquals("1243", container.getNumberOfRuntime());
    RandomElement element = container.getRandomElement();
    assertNotNull(element);
    assertEquals("foo", element.getAttr1());
}
Also used : Container(org.glassfish.api.admin.config.Container) Config(com.sun.enterprise.config.serverbeans.Config) Domain(com.sun.enterprise.config.serverbeans.Domain) ConfigApiTest(com.sun.enterprise.configapi.tests.ConfigApiTest) Test(org.junit.Test)

Example 40 with Config

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

the class GrizzlyConfigSchemaMigrator method migrateThreadPools.

private void migrateThreadPools(ThreadPools threadPools) throws TransactionFailure {
    final Config config = threadPools.getParent(Config.class);
    final NetworkListeners networkListeners = config.getNetworkConfig().getNetworkListeners();
    threadPools.getThreadPool().addAll(networkListeners.getThreadPool());
    ConfigSupport.apply(new SingleConfigCode<NetworkListeners>() {

        public Object run(NetworkListeners param) {
            param.getThreadPool().clear();
            return null;
        }
    }, networkListeners);
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)152 ActionReport (org.glassfish.api.ActionReport)73 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)50 PropertyVetoException (java.beans.PropertyVetoException)34 Target (org.glassfish.internal.api.Target)31 CommandTarget (org.glassfish.config.support.CommandTarget)30 Properties (java.util.Properties)28 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)23 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 HashMap (java.util.HashMap)17 Server (com.sun.enterprise.config.serverbeans.Server)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Logger (java.util.logging.Logger)14 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)13 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10 Level (java.util.logging.Level)10 LogRecord (java.util.logging.LogRecord)10