Search in sources :

Example 31 with Target

use of org.glassfish.internal.api.Target 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().getHttp2Enabled()));
    if (Boolean.parseBoolean(protocol.getHttp().getHttp2Enabled())) {
        report.appendMessage(String.format("Push Enabled: %s\n", protocol.getHttp().getHttp2PushEnabled()));
        report.appendMessage(String.format("Cipher Check: %s\n", !Boolean.parseBoolean(protocol.getHttp().getHttp2DisableCipherCheck())));
        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().getHttp2Enabled());
    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().getHttp2DisableCipherCheck());
    properties.put("http2PushEnabled", protocol.getHttp().getHttp2PushEnabled());
    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 32 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class ListProtocols method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    final ActionReport report = context.getActionReport();
    List<Protocol> list = config.getNetworkConfig().getProtocols().getProtocol();
    for (Protocol protocol : list) {
        report.getTopMessagePart().addChild().setMessage(protocol.getName());
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 33 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class ConnectorDeployer method deleteResourceRef.

private void deleteResourceRef(String jndiName, String target) throws TransactionFailure {
    if (target.equals(DOMAIN)) {
        return;
    }
    if (domain.getConfigNamed(target) != null) {
        return;
    }
    Server server = configBeansUtilities.getServerNamed(target);
    if (server != null) {
        if (server.isResourceRefExists(jndiName)) {
            // delete ResourceRef for Server
            server.deleteResourceRef(jndiName);
        }
    } else {
        Cluster cluster = domain.getClusterNamed(target);
        if (cluster != null) {
            if (cluster.isResourceRefExists(jndiName)) {
                // delete ResourceRef of Cluster
                cluster.deleteResourceRef(jndiName);
                // delete ResourceRef for all instances of Cluster
                Target tgt = habitat.getService(Target.class);
                List<Server> instances = tgt.getInstances(target);
                for (Server svr : instances) {
                    if (svr.isResourceRefExists(jndiName)) {
                        svr.deleteResourceRef(jndiName);
                    }
                }
            }
        }
    }
}
Also used : Target(org.glassfish.internal.api.Target)

Example 34 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class SetHealthCheckServiceConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    report = context.getActionReport();
    if (report.getExtraProperties() == null) {
        report.setExtraProperties(new Properties());
    }
    targetConfig = targetUtil.getConfig(target);
    serviceType = parseServiceType(serviceName);
    if (serviceType == null) {
        String values = Arrays.asList(CheckerType.values()).stream().map(type -> type.name().toLowerCase().replace('_', '-')).collect(Collectors.joining(", "));
        report.setMessage("No such service: " + serviceName + ".\nChoose one of: " + values + ".\nThe name can also be given in short form consisting only of the first letters of each word.");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // update the service to unify the way it is printed later on
    serviceName = serviceType.name().toLowerCase().replace('_', '-');
    BaseHealthCheck<?, ?> service = getService();
    if (service == null) {
        report.appendMessage(strings.getLocalString("healthcheck.service.configure.status.error", "Service with name {0} could not be found.", serviceName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    updateServiceConfiguration(service);
}
Also used : Arrays(java.util.Arrays) HoggingThreadsChecker(fish.payara.nucleus.healthcheck.configuration.HoggingThreadsChecker) BaseThresholdHealthCheck(fish.payara.nucleus.healthcheck.preliminary.BaseThresholdHealthCheck) RestEndpoint(org.glassfish.api.admin.RestEndpoint) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) HealthCheckService(fish.payara.nucleus.healthcheck.HealthCheckService) Max(javax.validation.constraints.Max) Property(org.jvnet.hk2.config.types.Property) CheckerConfigurationType(fish.payara.nucleus.healthcheck.configuration.CheckerConfigurationType) Min(javax.validation.constraints.Min) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Target(org.glassfish.internal.api.Target) ThresholdDiagnosticsChecker(fish.payara.nucleus.healthcheck.configuration.ThresholdDiagnosticsChecker) List(java.util.List) Service(org.jvnet.hk2.annotations.Service) CommandTarget(org.glassfish.config.support.CommandTarget) Domain(com.sun.enterprise.config.serverbeans.Domain) SystemPropertyConstants(com.sun.enterprise.util.SystemPropertyConstants) HealthCheckConstants(fish.payara.nucleus.healthcheck.HealthCheckConstants) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) HealthCheckServiceConfiguration(fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration) CheckerType(fish.payara.nucleus.healthcheck.configuration.CheckerType) Param(org.glassfish.api.Param) MonitoredMetric(fish.payara.nucleus.healthcheck.configuration.MonitoredMetric) CommandLock(org.glassfish.api.admin.CommandLock) HealthCheckExecutionOptions(fish.payara.nucleus.healthcheck.HealthCheckExecutionOptions) Level(java.util.logging.Level) 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) LocalStringManagerImpl(com.sun.enterprise.util.LocalStringManagerImpl) BiConsumer(java.util.function.BiConsumer) RestEndpoints(org.glassfish.api.admin.RestEndpoints) AdminCommand(org.glassfish.api.admin.AdminCommand) Properties(java.util.Properties) StuckThreadsChecker(fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker) MicroProfileMetricsChecker(fish.payara.nucleus.healthcheck.configuration.MicroProfileMetricsChecker) TargetType(org.glassfish.config.support.TargetType) Checker(fish.payara.nucleus.healthcheck.configuration.Checker) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) BaseHealthCheck(fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) Config(com.sun.enterprise.config.serverbeans.Config) Properties(java.util.Properties)

Example 35 with Target

use of org.glassfish.internal.api.Target in project Payara by payara.

the class ResourceUtil method createResourceRef.

public void createResourceRef(String jndiName, String enabled, String target) throws TransactionFailure {
    if (target.equals(DOMAIN)) {
        return;
    }
    Config config = domain.getConfigNamed(target);
    if (config != null) {
        if (!config.isResourceRefExists(jndiName)) {
            config.createResourceRef(enabled, jndiName);
        }
    // return;
    }
    Server server = configBeansUtilities.getServerNamed(target);
    if (server != null) {
        if (!server.isResourceRefExists(jndiName)) {
            // create new ResourceRef as a child of Server
            server.createResourceRef(enabled, jndiName);
        }
    } else {
        Cluster cluster = domain.getClusterNamed(target);
        if (cluster != null) {
            if (!cluster.isResourceRefExists(jndiName)) {
                // create new ResourceRef as a child of Cluster
                cluster.createResourceRef(enabled, jndiName);
                // create new ResourceRef for all instances of Cluster
                Target tgt = targetProvider.get();
                List<Server> instances = tgt.getInstances(target);
                for (Server svr : instances) {
                    if (!svr.isResourceRefExists(jndiName)) {
                        svr.createResourceRef(enabled, jndiName);
                    }
                }
            }
        }
    }
}
Also used : Target(org.glassfish.internal.api.Target)

Aggregations

Target (org.glassfish.internal.api.Target)39 CommandTarget (org.glassfish.config.support.CommandTarget)35 Config (com.sun.enterprise.config.serverbeans.Config)32 ActionReport (org.glassfish.api.ActionReport)32 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 PropertyVetoException (java.beans.PropertyVetoException)11 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)11 Protocols (org.glassfish.grizzly.config.dom.Protocols)10 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)9 List (java.util.List)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 HttpService (com.sun.enterprise.config.serverbeans.HttpService)4 SystemPropertyConstants (com.sun.enterprise.util.SystemPropertyConstants)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 Logger (java.util.logging.Logger)3 Inject (javax.inject.Inject)3 I18n (org.glassfish.api.I18n)3 Param (org.glassfish.api.Param)3