Search in sources :

Example 1 with AdminCommandContext

use of org.glassfish.api.admin.AdminCommandContext in project Payara by payara.

the class GetHttpListener method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    // Check that a configuration can be found
    if (targetUtil.getConfig(target) == null) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
        return;
    }
    Config config = targetUtil.getConfig(target);
    // Check that a matching listener can be found
    List<NetworkListener> listeners = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
    Optional<NetworkListener> optionalListener = listeners.stream().filter(listener -> listener.getName().equals(listenerName)).findFirst();
    if (!optionalListener.isPresent()) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_NETWORK_LISTENER), listenerName, target));
        return;
    }
    NetworkListener listener = optionalListener.get();
    // Write message body
    report.appendMessage(String.format("Name: %s\n", listener.getName()));
    report.appendMessage(String.format("Enabled: %s\n", listener.getEnabled()));
    report.appendMessage(String.format("Port: %s\n", listener.getPort()));
    report.appendMessage(String.format("Address: %s\n", listener.getAddress()));
    report.appendMessage(String.format("Protocol: %s\n", listener.getProtocol()));
    if (verbose) {
        report.appendMessage(String.format("Transport: %s\n", listener.getTransport()));
        report.appendMessage(String.format("Type: %s\n", listener.getType()));
        report.appendMessage(String.format("Thread Pool: %s\n", listener.getThreadPool()));
        report.appendMessage(String.format("JK Enabled: %s\n", listener.getJkEnabled()));
        report.appendMessage(String.format("JK Configuration File: %s\n", listener.getJkConfigurationFile()));
    }
    // Write the variables as properties
    Properties properties = new Properties();
    properties.put("name", listener.getName());
    properties.put("enabled", listener.getEnabled());
    properties.put("port", listener.getPort());
    properties.put("address", listener.getAddress());
    properties.put("protocol", listener.getProtocol());
    properties.put("transport", listener.getTransport());
    properties.put("type", listener.getType());
    properties.put("threadPool", listener.getThreadPool());
    properties.put("jkEnabled", listener.getJkEnabled());
    properties.put("jkConfigurationFile", listener.getJkConfigurationFile());
    report.setExtraProperties(properties);
}
Also used : Param(org.glassfish.api.Param) LogFacade(org.glassfish.web.admin.LogFacade) RestEndpoint(org.glassfish.api.admin.RestEndpoint) CommandLock(org.glassfish.api.admin.CommandLock) MessageFormat(java.text.MessageFormat) I18n(org.glassfish.api.I18n) PerLookup(org.glassfish.hk2.api.PerLookup) Inject(javax.inject.Inject) ActionReport(org.glassfish.api.ActionReport) ExecuteOn(org.glassfish.api.admin.ExecuteOn) RuntimeType(org.glassfish.api.admin.RuntimeType) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) RestEndpoints(org.glassfish.api.admin.RestEndpoints) AdminCommand(org.glassfish.api.admin.AdminCommand) Properties(java.util.Properties) TargetType(org.glassfish.config.support.TargetType) Logger(java.util.logging.Logger) List(java.util.List) Target(org.glassfish.internal.api.Target) Service(org.jvnet.hk2.annotations.Service) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) CommandTarget(org.glassfish.config.support.CommandTarget) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Optional(java.util.Optional) SystemPropertyConstants(com.sun.enterprise.util.SystemPropertyConstants) Config(com.sun.enterprise.config.serverbeans.Config) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 2 with AdminCommandContext

use of org.glassfish.api.admin.AdminCommandContext in project Payara by payara.

the class ListJdbcResourcesTest method testExecuteSuccessListOriginal.

/**
 * Test of execute method, of class ListJdbcResources.
 * list-jdbc-resources
 */
@Test
public void testExecuteSuccessListOriginal() {
    // List the original set of JDBC Resources
    // Get an instance of the ListJdbcResources command
    ListJdbcResources listCommand = habitat.getService(ListJdbcResources.class);
    AdminCommandContext context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
    // Call CommandRunnerImpl.doCommand(..) to execute the command
    cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
    List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
    assertEquals(origNum, list.size());
    // Check the exit code is SUCCESS
    assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) MessagePart(org.glassfish.api.ActionReport.MessagePart) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 3 with AdminCommandContext

use of org.glassfish.api.admin.AdminCommandContext in project Payara by payara.

the class RuntimeRootImpl method restartDomain.

public void restartDomain() {
    final ModulesRegistry registry = InjectedValues.getInstance().getModulesRegistry();
    final AdminCommandContext ctx = new AdminCommandContextImpl(AMXLoggerInfo.getLogger(), new PlainTextActionReporter());
    final AdminCommand cmd = new RestartDomainCommand(registry);
    cmd.execute(ctx);
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) AdminCommand(org.glassfish.api.admin.AdminCommand) RestartDomainCommand(com.sun.enterprise.v3.admin.RestartDomainCommand) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) PlainTextActionReporter(com.sun.enterprise.v3.common.PlainTextActionReporter)

Example 4 with AdminCommandContext

use of org.glassfish.api.admin.AdminCommandContext in project Payara by payara.

the class GetProtocol method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    // Check that a configuration can be found
    if (targetUtil.getConfig(target) == null) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
        return;
    }
    Config config = targetUtil.getConfig(target);
    // Check that a matching listener can be found
    List<Protocol> protocols = config.getNetworkConfig().getProtocols().getProtocol();
    Optional<Protocol> optionalProtocol = protocols.stream().filter(protocol -> protocol.getName().equals(protocolName)).findFirst();
    if (!optionalProtocol.isPresent()) {
        report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_PROTOCOL), protocolName, target));
        return;
    }
    Protocol protocol = optionalProtocol.get();
    // Write message body
    report.appendMessage(String.format("Name: %s\n", protocol.getName()));
    // Write HTTP config options
    report.appendMessage("\nHTTP:\n");
    report.appendMessage(String.format("Server Name: %s\n", protocol.getHttp().getServerName()));
    report.appendMessage(String.format("Max Connections: %s seconds\n", protocol.getHttp().getMaxConnections()));
    report.appendMessage(String.format("Default Virtual Server: %s\n", protocol.getHttp().getDefaultVirtualServer()));
    report.appendMessage(String.format("Server Header: %s\n", protocol.getHttp().getServerHeader()));
    report.appendMessage(String.format("X-Powered-By: %s\n", protocol.getHttp().getXpoweredBy()));
    if (verbose) {
        report.appendMessage(String.format("Request Timeout: %s seconds\n", protocol.getHttp().getRequestTimeoutSeconds()));
        report.appendMessage(String.format("Timeout: %s seconds\n", protocol.getHttp().getTimeoutSeconds()));
        report.appendMessage(String.format("DNS Lookup Enabled: %s\n", protocol.getHttp().getDnsLookupEnabled()));
        report.appendMessage(String.format("X Frame Options: %s\n", protocol.getHttp().getXframeOptions()));
    }
    // Write HTTP/2 config options
    report.appendMessage("\nHTTP/2:\n");
    report.appendMessage(String.format("Enabled: %s\n", protocol.getHttp().isHttp2Enabled()));
    if (protocol.getHttp().isHttp2Enabled()) {
        report.appendMessage(String.format("Push Enabled: %s\n", protocol.getHttp().isHttp2PushEnabled()));
        report.appendMessage(String.format("Cipher Check: %s\n", !protocol.getHttp().isHttp2DisableCipherCheck()));
        if (verbose) {
            report.appendMessage(String.format("Max Concurrent Streams: %s\n", protocol.getHttp().getHttp2MaxConcurrentStreams()));
            report.appendMessage(String.format("Initial Window Size: %s bytes\n", protocol.getHttp().getHttp2InitialWindowSizeInBytes()));
            report.appendMessage(String.format("Max Frame Payload Size: %s bytes\n", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes()));
            report.appendMessage(String.format("Max Header List Size: %s bytes\n", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes()));
            report.appendMessage(String.format("Streams High Water Mark: %s\n", protocol.getHttp().getHttp2StreamsHighWaterMark()));
            report.appendMessage(String.format("Clean Percentage: %s\n", protocol.getHttp().getHttp2CleanPercentage()));
            report.appendMessage(String.format("Clean Frequency Check: %s\n", protocol.getHttp().getHttp2CleanFrequencyCheck()));
        }
    }
    // Write the variables as properties
    Properties properties = new Properties();
    properties.put("name", protocol.getName());
    properties.put("serverName", protocol.getHttp().getServerName() == null ? "null" : protocol.getHttp().getServerName());
    properties.put("maxConnections", protocol.getHttp().getMaxConnections());
    properties.put("defaultVirtualServer", protocol.getHttp().getDefaultVirtualServer());
    properties.put("serverHeader", protocol.getHttp().getServerHeader());
    properties.put("xPoweredBy", protocol.getHttp().getXpoweredBy());
    properties.put("requestTimeoutSeconds", protocol.getHttp().getRequestTimeoutSeconds());
    properties.put("timeoutSeconds", protocol.getHttp().getTimeoutSeconds());
    properties.put("dnsLookupEnabled", protocol.getHttp().getDnsLookupEnabled());
    properties.put("xFrameOptions", protocol.getHttp().getXframeOptions());
    properties.put("http2Enabled", protocol.getHttp().isHttp2Enabled());
    properties.put("http2MaxConcurrentStreams", protocol.getHttp().getHttp2MaxConcurrentStreams());
    properties.put("http2InitialWindowSizeInBytes", protocol.getHttp().getHttp2InitialWindowSizeInBytes());
    properties.put("http2MaxFramePayloadSizeInBytes", protocol.getHttp().getHttp2MaxFramePayloadSizeInBytes());
    properties.put("http2MaxHeaderListSizeInBytes", protocol.getHttp().getHttp2MaxHeaderListSizeInBytes());
    properties.put("http2StreamsHighWaterMark", protocol.getHttp().getHttp2StreamsHighWaterMark());
    properties.put("http2CleanPercentage", protocol.getHttp().getHttp2CleanPercentage());
    properties.put("http2CleanFrequencyCheck", protocol.getHttp().getHttp2CleanFrequencyCheck());
    properties.put("http2DisableCipherCheck", protocol.getHttp().isHttp2DisableCipherCheck());
    properties.put("http2PushEnabled", protocol.getHttp().isHttp2PushEnabled());
    report.setExtraProperties(properties);
}
Also used : Param(org.glassfish.api.Param) LogFacade(org.glassfish.web.admin.LogFacade) RestEndpoint(org.glassfish.api.admin.RestEndpoint) CommandLock(org.glassfish.api.admin.CommandLock) MessageFormat(java.text.MessageFormat) I18n(org.glassfish.api.I18n) PerLookup(org.glassfish.hk2.api.PerLookup) Inject(javax.inject.Inject) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) ExecuteOn(org.glassfish.api.admin.ExecuteOn) RuntimeType(org.glassfish.api.admin.RuntimeType) RestEndpoints(org.glassfish.api.admin.RestEndpoints) AdminCommand(org.glassfish.api.admin.AdminCommand) Properties(java.util.Properties) TargetType(org.glassfish.config.support.TargetType) Logger(java.util.logging.Logger) List(java.util.List) Target(org.glassfish.internal.api.Target) Service(org.jvnet.hk2.annotations.Service) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) CommandTarget(org.glassfish.config.support.CommandTarget) HttpService(com.sun.enterprise.config.serverbeans.HttpService) Optional(java.util.Optional) SystemPropertyConstants(com.sun.enterprise.util.SystemPropertyConstants) Config(com.sun.enterprise.config.serverbeans.Config) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol) Properties(java.util.Properties)

Example 5 with AdminCommandContext

use of org.glassfish.api.admin.AdminCommandContext in project Payara by payara.

the class SetHazelcastConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final AdminCommandContext theContext = context;
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    if (!validate(actionReport)) {
        return;
    }
    HazelcastRuntimeConfiguration hazelcastRuntimeConfiguration = domain.getExtensionByType(HazelcastRuntimeConfiguration.class);
    if (hazelcastRuntimeConfiguration != null) {
        try {
            ConfigSupport.apply(new SingleConfigCode<HazelcastRuntimeConfiguration>() {

                @Override
                public Object run(final HazelcastRuntimeConfiguration hazelcastRuntimeConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                    if (startPort != null) {
                        hazelcastRuntimeConfigurationProxy.setStartPort(startPort);
                    }
                    if (multiCastGroup != null) {
                        hazelcastRuntimeConfigurationProxy.setMulticastGroup(multiCastGroup);
                    }
                    if (multicastPort != null) {
                        hazelcastRuntimeConfigurationProxy.setMulticastPort(multicastPort);
                    }
                    if (configFile != null) {
                        hazelcastRuntimeConfigurationProxy.setHazelcastConfigurationFile(configFile);
                    }
                    if (hostawarePartitioning != null) {
                        hazelcastRuntimeConfigurationProxy.setHostAwarePartitioning(hostawarePartitioning.toString());
                    }
                    if (hzClusterName != null) {
                        hazelcastRuntimeConfigurationProxy.setClusterGroupName(hzClusterName);
                    }
                    if (hzClusterPassword != null) {
                        hazelcastRuntimeConfigurationProxy.setClusterGroupPassword(hzClusterPassword);
                    }
                    if (licenseKey != null) {
                        hazelcastRuntimeConfigurationProxy.setLicenseKey(licenseKey);
                    }
                    if (dasPublicAddress != null) {
                        hazelcastRuntimeConfigurationProxy.setDASPublicAddress(dasPublicAddress);
                    }
                    if (dasBindAddress != null) {
                        hazelcastRuntimeConfigurationProxy.setDASBindAddress(dasBindAddress);
                    }
                    if (dasPort != null) {
                        hazelcastRuntimeConfigurationProxy.setDasPort(dasPort);
                    }
                    if (clusterMode != null) {
                        hazelcastRuntimeConfigurationProxy.setDiscoveryMode(clusterMode);
                    }
                    if (tcpipMembers != null) {
                        hazelcastRuntimeConfigurationProxy.setTcpipMembers(tcpipMembers);
                    }
                    if (interfaces != null) {
                        hazelcastRuntimeConfigurationProxy.setInterface(interfaces);
                    }
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return null;
                }
            }, hazelcastRuntimeConfiguration);
            // get the configs that need the change applied if target is domain it is all configs
            Config config = targetUtil.getConfig(target);
            List<Config> configsToApply = new ArrayList<>(5);
            if (config == null && target.equals("domain")) {
                configsToApply.addAll(domain.getConfigs().getConfig());
            } else if (config != null) {
                configsToApply.add(config);
            }
            for (Config configToApply : configsToApply) {
                HazelcastConfigSpecificConfiguration nodeConfiguration = configToApply.getExtensionByType(HazelcastConfigSpecificConfiguration.class);
                ConfigSupport.apply(new SingleConfigCode<HazelcastConfigSpecificConfiguration>() {

                    @Override
                    public Object run(final HazelcastConfigSpecificConfiguration hazelcastRuntimeConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                        if (jndiName != null) {
                            hazelcastRuntimeConfigurationProxy.setJNDIName(jndiName);
                        }
                        if (enabled != null) {
                            hazelcastRuntimeConfigurationProxy.setEnabled(enabled.toString());
                        }
                        if (lite != null) {
                            hazelcastRuntimeConfigurationProxy.setLite(lite.toString());
                        }
                        if (cacheManagerJndiName != null) {
                            hazelcastRuntimeConfigurationProxy.setCacheManagerJNDIName(cacheManagerJndiName);
                        }
                        if (cachingProviderJndiName != null) {
                            hazelcastRuntimeConfigurationProxy.setCachingProviderJNDIName(cachingProviderJndiName);
                        }
                        if (executorPoolSize != null) {
                            hazelcastRuntimeConfigurationProxy.setExecutorPoolSize(executorPoolSize);
                        }
                        if (executorQueueCapacity != null) {
                            hazelcastRuntimeConfigurationProxy.setExecutorQueueCapacity(executorQueueCapacity);
                        }
                        if (scheduledExecutorPoolSize != null) {
                            hazelcastRuntimeConfigurationProxy.setScheduledExecutorPoolSize(scheduledExecutorPoolSize);
                        }
                        if (scheduledExecutorQueueCapacity != null) {
                            hazelcastRuntimeConfigurationProxy.setScheduledExecutorQueueCapacity(scheduledExecutorQueueCapacity);
                        }
                        if (memberName != null) {
                            hazelcastRuntimeConfigurationProxy.setMemberName(memberName);
                        }
                        if (memberGroup != null) {
                            hazelcastRuntimeConfigurationProxy.setMemberGroup(memberGroup);
                        }
                        actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                        return null;
                    }
                }, nodeConfiguration);
            }
        } catch (TransactionFailure ex) {
            logger.log(Level.WARNING, "Exception during command ", ex);
            actionReport.setMessage(ex.getCause().getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        if (dynamic) {
            boolean isEnabled = false;
            if (enabled != null) {
                isEnabled = enabled;
            } else {
                isEnabled = hazelcast.isEnabled();
            }
            // this command runs on all instances so they can update their configuration.
            if ("domain".equals(target)) {
                hazelcast.setEnabled(isEnabled);
            } else {
                for (Server targetServer : targetUtil.getInstances(target)) {
                    if (server.getInstanceName().equals(targetServer.getName())) {
                        hazelcast.setEnabled(isEnabled);
                    }
                }
            }
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) HazelcastRuntimeConfiguration(fish.payara.nucleus.hazelcast.HazelcastRuntimeConfiguration) Server(com.sun.enterprise.config.serverbeans.Server) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) HazelcastConfigSpecificConfiguration(fish.payara.nucleus.hazelcast.HazelcastConfigSpecificConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) PropertyVetoException(java.beans.PropertyVetoException) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext)

Aggregations

AdminCommandContext (org.glassfish.api.admin.AdminCommandContext)8 ActionReport (org.glassfish.api.ActionReport)5 Properties (java.util.Properties)4 Config (com.sun.enterprise.config.serverbeans.Config)3 AdminCommand (org.glassfish.api.admin.AdminCommand)3 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)3 Test (org.junit.Test)3 HttpService (com.sun.enterprise.config.serverbeans.HttpService)2 SystemPropertyConstants (com.sun.enterprise.util.SystemPropertyConstants)2 PlainTextActionReporter (com.sun.enterprise.v3.common.PlainTextActionReporter)2 MessageFormat (java.text.MessageFormat)2 List (java.util.List)2 Optional (java.util.Optional)2 Logger (java.util.logging.Logger)2 Inject (javax.inject.Inject)2 I18n (org.glassfish.api.I18n)2 Param (org.glassfish.api.Param)2 CommandLock (org.glassfish.api.admin.CommandLock)2 ExecuteOn (org.glassfish.api.admin.ExecuteOn)2 RestEndpoint (org.glassfish.api.admin.RestEndpoint)2