Search in sources :

Example 96 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class SetNetworkListenerConfiguration method shutdownChange.

private void shutdownChange() {
    List<UnprocessedChangeEvent> processed = new ArrayList<>();
    for (UnprocessedChangeEvents unchangedEvents : ucl.getUnprocessedChangeEvents()) {
        for (UnprocessedChangeEvent unprocessedEvent : unchangedEvents.getUnprocessed()) {
            PropertyChangeEvent event = unprocessedEvent.getEvent();
            if (event.getSource().getClass().equals(this.getClass()) && event.getPropertyName().equals("port")) {
                SetNetworkListenerConfiguration oldConfig = (SetNetworkListenerConfiguration) event.getSource();
                NetworkListeners listeners = oldConfig.confign.getNetworkListeners();
                for (NetworkListener listener : listeners.getNetworkListener()) {
                    if (listener.getName().equals(oldConfig.listenerName)) {
                        try {
                            ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

                                @Override
                                public Object run(final NetworkListener listenerProxy) throws PropertyVetoException, TransactionFailure {
                                    listenerProxy.setPort((event.getNewValue().toString()));
                                    return null;
                                }
                            }, listener);
                        } catch (TransactionFailure ex) {
                            Logger.getLogger(SetNetworkListenerConfiguration.class.getName()).log(Level.SEVERE, null, ex);
                        } finally {
                            processed.add(unprocessedEvent);
                        }
                    }
                }
            }
        }
    }
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) PropertyVetoException(java.beans.PropertyVetoException) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 97 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class CreateHttpRedirect method execute.

// ----------------------------------------------- Methods from AdminCommand
@Override
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();
    // check for duplicates
    Protocols protocols = config.getNetworkConfig().getProtocols();
    Protocol protocol = null;
    for (Protocol p : protocols.getProtocol()) {
        if (protocolName.equals(p.getName())) {
            protocol = p;
        }
    }
    if (protocol == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (protocol.getHttpRedirect() != null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL_DUPLICATE), protocolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Protocol>() {

            public Object run(Protocol param) throws TransactionFailure {
                HttpRedirect httpRedirect = param.createChild(HttpRedirect.class);
                httpRedirect.setPort(port);
                httpRedirect.setSecure(secure);
                param.setHttpRedirect(httpRedirect);
                return httpRedirect;
            }
        }, protocol);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL), protocolName) + (e.getMessage() == null ? "No reason given." : e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Protocols(org.glassfish.grizzly.config.dom.Protocols) HttpRedirect(org.glassfish.grizzly.config.dom.HttpRedirect) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Example 98 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class SetRequestTracingConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    Config config = targetUtil.getConfig(target);
    final RequestTracingServiceConfiguration requestTracingServiceConfiguration = config.getExtensionByType(RequestTracingServiceConfiguration.class);
    if (requestTracingServiceConfiguration != null) {
        final Set<String> notifierNames = NotifierUtils.getNotifierNames(serviceLocator);
        try {
            ConfigSupport.apply(new SingleConfigCode<RequestTracingServiceConfiguration>() {

                @Override
                public Object run(final RequestTracingServiceConfiguration proxy) throws PropertyVetoException, TransactionFailure {
                    boolean warn = false;
                    if (enabled != null) {
                        proxy.enabled(enabled.toString());
                    }
                    if (sampleRate != null) {
                        proxy.setSampleRate(sampleRate);
                    }
                    if (adaptiveSamplingEnabled != null) {
                        proxy.setAdaptiveSamplingEnabled(adaptiveSamplingEnabled.toString());
                    }
                    if (adaptiveSamplingTargetCount != null) {
                        proxy.setAdaptiveSamplingTargetCount(adaptiveSamplingTargetCount);
                    }
                    if (adaptiveSamplingTimeValue != null) {
                        proxy.setAdaptiveSamplingTimeValue(adaptiveSamplingTimeValue.toString());
                    }
                    if (adaptiveSamplingTimeUnit != null) {
                        proxy.setAdaptiveSamplingTimeUnit(adaptiveSamplingTimeUnit);
                    }
                    if (applicationsOnlyEnabled != null) {
                        proxy.setApplicationsOnlyEnabled(applicationsOnlyEnabled.toString());
                    }
                    if (thresholdValue != null) {
                        proxy.setThresholdValue(thresholdValue);
                    }
                    if (thresholdUnit != null) {
                        proxy.setThresholdUnit(thresholdUnit);
                    }
                    if (sampleRateFirstEnabled != null) {
                        proxy.setSampleRateFirstEnabled(sampleRateFirstEnabled.toString());
                    }
                    if (traceStoreSize != null) {
                        warn = !traceStoreSize.toString().equals(proxy.getTraceStoreSize());
                        proxy.setTraceStoreSize(traceStoreSize.toString());
                    }
                    if (traceStoreTimeout != null) {
                        warn = !traceStoreTimeout.equals(proxy.getTraceStoreTimeout());
                        proxy.setTraceStoreTimeout(traceStoreTimeout);
                    }
                    if (reservoirSamplingEnabled != null) {
                        proxy.setReservoirSamplingEnabled(reservoirSamplingEnabled.toString());
                    }
                    if (historicTraceStoreEnabled != null) {
                        proxy.setHistoricTraceStoreEnabled(historicTraceStoreEnabled.toString());
                    }
                    if (historicTraceStoreSize != null) {
                        warn = !historicTraceStoreSize.toString().equals(proxy.getHistoricTraceStoreSize());
                        proxy.setHistoricTraceStoreSize(historicTraceStoreSize.toString());
                    }
                    if (historicTraceStoreTimeout != null) {
                        warn = !historicTraceStoreTimeout.equals(proxy.getHistoricTraceStoreTimeout());
                        proxy.setHistoricTraceStoreTimeout(historicTraceStoreTimeout);
                    }
                    List<String> notifiers = proxy.getNotifierList();
                    if (enableNotifiers != null) {
                        for (String notifier : enableNotifiers) {
                            if (notifierNames.contains(notifier)) {
                                if (!notifiers.contains(notifier)) {
                                    notifiers.add(notifier);
                                }
                            } else {
                                throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
                            }
                        }
                    }
                    if (disableNotifiers != null) {
                        for (String notifier : disableNotifiers) {
                            if (notifierNames.contains(notifier)) {
                                notifiers.remove(notifier);
                            } else {
                                throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
                            }
                        }
                    }
                    if (setNotifiers != null) {
                        notifiers.clear();
                        for (String notifier : setNotifiers) {
                            if (notifierNames.contains(notifier)) {
                                if (!notifiers.contains(notifier)) {
                                    notifiers.add(notifier);
                                }
                            } else {
                                throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
                            }
                        }
                    }
                    actionReport.setActionExitCode(ExitCode.SUCCESS);
                    if (warn) {
                        actionReport.setMessage(STRINGS.get("requesttracing.configure.store.size.warning"));
                    }
                    return proxy;
                }
            }, requestTracingServiceConfiguration);
        } catch (TransactionFailure ex) {
            actionReport.failure(logger, ex.getCause().getMessage());
            return;
        }
    }
    if (dynamic) {
        if (server.isDas()) {
            if (targetUtil.getConfig(target).isDas()) {
                configureDynamically(actionReport);
            }
        } else {
            configureDynamically(actionReport);
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyChangeEvent(java.beans.PropertyChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) PropertyVetoException(java.beans.PropertyVetoException) List(java.util.List) RequestTracingServiceConfiguration(fish.payara.nucleus.requesttracing.configuration.RequestTracingServiceConfiguration)

Example 99 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class HealthCheckConfigurer method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    Properties extraProperties = actionReport.getExtraProperties();
    if (extraProperties == null) {
        extraProperties = new Properties();
        actionReport.setExtraProperties(extraProperties);
    }
    Config config = targetUtil.getConfig(target);
    final HealthCheckServiceConfiguration healthCheckServiceConfiguration = config.getExtensionByType(HealthCheckServiceConfiguration.class);
    if (healthCheckServiceConfiguration != null) {
        try {
            final Set<String> notifierNames = NotifierUtils.getNotifierNames(serviceLocator);
            ConfigSupport.apply(new SingleConfigCode<HealthCheckServiceConfiguration>() {

                @Override
                public Object run(final HealthCheckServiceConfiguration proxy) throws PropertyVetoException, TransactionFailure {
                    if (enabled != null) {
                        proxy.enabled(enabled.toString());
                    }
                    if (historicalTraceEnabled != null) {
                        proxy.setHistoricalTraceEnabled(historicalTraceEnabled.toString());
                    }
                    if (historicalTraceStoreSize != null) {
                        proxy.setHistoricalTraceStoreSize(historicalTraceStoreSize.toString());
                    }
                    if (historicalTraceStoreTimeout != null) {
                        proxy.setHistoricalTraceStoreTimeout(historicalTraceStoreTimeout.toString());
                    }
                    List<String> notifiers = proxy.getNotifierList();
                    if (enableNotifiers != null) {
                        for (String notifier : enableNotifiers) {
                            if (notifierNames.contains(notifier)) {
                                notifiers.add(notifier);
                            } else {
                                throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
                            }
                        }
                    }
                    if (disableNotifiers != null) {
                        for (String notifier : disableNotifiers) {
                            if (notifierNames.contains(notifier)) {
                                notifiers.remove(notifier);
                            } else {
                                throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
                            }
                        }
                    }
                    if (setNotifiers != null) {
                        notifiers.clear();
                        for (String notifier : setNotifiers) {
                            if (notifierNames.contains(notifier)) {
                                if (!notifiers.contains(notifier)) {
                                    notifiers.add(notifier);
                                }
                            } else {
                                throw new PropertyVetoException("Unrecognised notifier " + notifier, new PropertyChangeEvent(proxy, "notifiers", notifiers, notifiers));
                            }
                        }
                    }
                    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                    return proxy;
                }
            }, healthCheckServiceConfiguration);
        } catch (TransactionFailure ex) {
            logger.log(Level.WARNING, "Exception during command ", ex);
            actionReport.setMessage(ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (dynamic) {
        if (server.isDas()) {
            if (targetUtil.getConfig(target).isDas()) {
                configureDynamically();
            }
        } else {
            // apply as not the DAS so implicitly it is for us
            configureDynamically();
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyChangeEvent(java.beans.PropertyChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) HealthCheckServiceConfiguration(fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) PropertyVetoException(java.beans.PropertyVetoException) List(java.util.List)

Example 100 with SingleConfigCode

use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.

the class ServerConfigSource method setValue.

public boolean setValue(final String propertyName, final String propertyValue) throws TransactionFailure {
    boolean result = false;
    Server config = domainConfiguration.getServerNamed(configurationName);
    if (config != null) {
        Property p = config.getProperty(PROPERTY_PREFIX + propertyName);
        if (p == null) {
            ConfigSupport.apply(new SingleConfigCode<Server>() {

                @Override
                public Object run(Server configuration) throws TransactionFailure, PropertyVetoException {
                    Property prop = configuration.createChild(Property.class);
                    prop.setName(PROPERTY_PREFIX + propertyName);
                    prop.setValue(propertyValue);
                    configuration.getProperty().add(prop);
                    return null;
                }
            }, config);
        } else {
            ConfigSupport.apply(new SingleConfigCode<Property>() {

                @Override
                public Object run(Property config) throws TransactionFailure, PropertyVetoException {
                    config.setValue(propertyValue);
                    return null;
                }
            }, p);
        }
        result = true;
    }
    return result;
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PropertyVetoException(java.beans.PropertyVetoException) Server(com.sun.enterprise.config.serverbeans.Server) Property(org.jvnet.hk2.config.types.Property)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)153 PropertyVetoException (java.beans.PropertyVetoException)130 ActionReport (org.glassfish.api.ActionReport)76 Config (com.sun.enterprise.config.serverbeans.Config)47 Property (org.jvnet.hk2.config.types.Property)27 Resources (com.sun.enterprise.config.serverbeans.Resources)25 List (java.util.List)23 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)19 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 CommandTarget (org.glassfish.config.support.CommandTarget)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Target (org.glassfish.internal.api.Target)15 Test (org.junit.Test)15 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)13 ArrayList (java.util.ArrayList)11 Protocols (org.glassfish.grizzly.config.dom.Protocols)11 Resource (com.sun.enterprise.config.serverbeans.Resource)9 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)9 Properties (java.util.Properties)9