Search in sources :

Example 6 with SystemProperty

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

the class PortManager method changeSystemProperty.

private void changeSystemProperty(List<SystemProperty> sps, String name, String port) throws PropertyVetoException, TransactionFailure {
    for (SystemProperty sp : sps) {
        if (name.equals(sp.getName())) {
            sp.setValue(port);
            return;
        }
    }
    // does not exist -- let's add one!
    SystemProperty sp = newServer.createChild(SystemProperty.class);
    sp.setName(name);
    sp.setValue(port);
    sps.add(sp);
}
Also used : SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty)

Example 7 with SystemProperty

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

the class PortUtils method checkInternalConsistency.

/**
 * Make sure all ports that are specified by the user make sense.
 * @param server The new Server element
 * @return null if all went OK.  Otherwise return a String with the error message.
 */
static void checkInternalConsistency(Server server) throws TransactionFailure {
    // Make sure all the system properties for ports have different numbers.
    List<SystemProperty> sysProps = server.getSystemProperty();
    Set<Integer> ports = new TreeSet<Integer>();
    for (SystemProperty sp : sysProps) {
        String name = sp.getName();
        if (PORTSLIST.contains(name)) {
            String val = sp.getValue();
            try {
                boolean wasAdded = ports.add(Integer.parseInt(val));
                if (// TODO unit test
                !wasAdded)
                    throw new TransactionFailure(Strings.get("PortUtils.duplicate_port", val, server.getName()));
            } catch (TransactionFailure tf) {
                // don't re-wrap the same Exception type!
                throw tf;
            } catch (Exception e) {
                // TODO unit test
                throw new TransactionFailure(Strings.get("PortUtils.non_int_port", val, server.getName()));
            }
        }
    }
    checkForLegalPorts(ports, server.getName());
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty)

Example 8 with SystemProperty

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

the class DynamicConfigListener method changed.

@Override
public synchronized UnprocessedChangeEvents changed(final PropertyChangeEvent[] events) {
    return ConfigSupport.sortAndDispatch(events, new Changed() {

        @Override
        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "NetworkConfig changed {0} {1} {2}", new Object[] { type, tClass, t });
            }
            if (tClass == NetworkListener.class && t instanceof NetworkListener) {
                return processNetworkListener(type, (NetworkListener) t, events);
            } else if (tClass == Http.class && t instanceof Http) {
                return processProtocol(type, (Protocol) t.getParent(), events);
            } else if (tClass == FileCache.class && t instanceof FileCache) {
                return processProtocol(type, (Protocol) t.getParent().getParent(), null);
            } else if (tClass == Ssl.class && t instanceof Ssl) {
                /*
                         * Make sure the SSL parent is in fact a protocol.  It could
                         * be a jmx-connector.
                     */
                final ConfigBeanProxy parent = t.getParent();
                if (parent instanceof Protocol) {
                    return processProtocol(type, (Protocol) parent, null);
                }
            } else if (tClass == Protocol.class && t instanceof Protocol) {
                return processProtocol(type, (Protocol) t, null);
            } else if (tClass == ThreadPool.class && t instanceof ThreadPool) {
                NotProcessed notProcessed = null;
                ThreadPool threadPool = (ThreadPool) t;
                for (NetworkListener listener : threadPool.findNetworkListeners()) {
                    notProcessed = processNetworkListener(type, listener, null);
                }
                // Throw an unprocessed event change if one hasn't already if HTTP or ThreadPool monitoring is enabled.
                MonitoringService ms = config.getMonitoringService();
                String threadPoolLevel = ms.getModuleMonitoringLevels().getThreadPool();
                String httpServiceLevel = ms.getModuleMonitoringLevels().getHttpService();
                if (((threadPoolLevel != null && !threadPoolLevel.equals(OFF)) || (httpServiceLevel != null && !httpServiceLevel.equals(OFF))) && notProcessed == null) {
                    notProcessed = new NotProcessed("Monitoring statistics will be incorrect for " + threadPool.getName() + " until restart due to changed attribute(s).");
                }
                return notProcessed;
            } else if (tClass == Transport.class && t instanceof Transport) {
                NotProcessed notProcessed = null;
                for (NetworkListener listener : ((Transport) t).findNetworkListeners()) {
                    notProcessed = processNetworkListener(type, listener, null);
                }
                return notProcessed;
            } else if (tClass == VirtualServer.class && t instanceof VirtualServer && !grizzlyService.hasMapperUpdateListener()) {
                return processVirtualServer(type, (VirtualServer) t);
            } else if (tClass == SystemProperty.class && t instanceof SystemProperty) {
                NetworkConfig networkConfig = config.getNetworkConfig();
                if ((networkConfig != null) && ((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
                    for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
                        if (listener.getPort().equals(((SystemProperty) t).getValue())) {
                            return processNetworkListener(Changed.TYPE.CHANGE, listener, events);
                        }
                    }
                }
                return null;
            }
            return null;
        }
    }, logger);
}
Also used : ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) Ssl(org.glassfish.grizzly.config.dom.Ssl) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) FileCache(org.glassfish.grizzly.config.dom.FileCache) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Changed(org.jvnet.hk2.config.Changed) NotProcessed(org.jvnet.hk2.config.NotProcessed) Protocol(org.glassfish.grizzly.config.dom.Protocol) Transport(org.glassfish.grizzly.config.dom.Transport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 9 with SystemProperty

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

the class CreateSystemProperties 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
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    String sysPropName = "";
    try {
        for (final Object key : properties.keySet()) {
            final String propName = (String) key;
            sysPropName = propName;
            // value of an existing property
            try {
                TranslatedConfigView.doSubstitution.set(Boolean.FALSE);
                if (spb.containsProperty(sysPropName) && spb.getSystemProperty(sysPropName).getValue().equals(properties.getProperty(propName))) {
                    continue;
                }
            } finally {
                TranslatedConfigView.doSubstitution.set(Boolean.TRUE);
            }
            ConfigSupport.apply(new SingleConfigCode<SystemPropertyBag>() {

                @Override
                public Object run(SystemPropertyBag param) throws PropertyVetoException, TransactionFailure {
                    // update existing system property
                    for (SystemProperty sysProperty : param.getSystemProperty()) {
                        if (sysProperty.getName().equals(propName)) {
                            Transaction t = Transaction.getTransaction(param);
                            sysProperty = t.enroll(sysProperty);
                            sysProperty.setValue(properties.getProperty(propName));
                            return sysProperty;
                        }
                    }
                    // create system-property
                    SystemProperty newSysProp = param.createChild(SystemProperty.class);
                    newSysProp.setName(propName);
                    newSysProp.setValue(properties.getProperty(propName));
                    param.getSystemProperty().add(newSysProp);
                    return newSysProp;
                }
            }, spb);
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("create.system.properties.failed", "System property {0} creation failed", sysPropName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("create.system.properties.failed", "System property {0} creation failed", sysPropName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transaction(org.jvnet.hk2.config.Transaction) SystemPropertyBag(com.sun.enterprise.config.serverbeans.SystemPropertyBag) ActionReport(org.glassfish.api.ActionReport) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) PropertyVetoException(java.beans.PropertyVetoException)

Example 10 with SystemProperty

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

the class CombinedJavaConfigSystemPropertyListener method changed.

/* force serial behavior; don't allow more than one thread to make a mess here */
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    // ignore a REMOVE and an ADD of the same value
    final UnprocessedChangeEvents unp = ConfigSupport.sortAndDispatch(events, new Changed() {

        @Override
        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tc, T t) {
            NotProcessed result = null;
            if (tc == Profiler.class) {
                result = new NotProcessed("Creation or changes to a profiler require restart");
            } else if (tc == Property.class && t.getParent().getClass() == JavaConfig.class) {
                result = new NotProcessed("Addition of properties to JavaConfig requires restart");
            } else if (tc == JavaConfig.class && t instanceof JavaConfig) {
                final JavaConfig njc = (JavaConfig) t;
                logFine(type, njc);
                // we must *always* check the jvm options, no way to know except by comparing,
                // plus we should send an appropriate message back for each removed/added item
                final List<String> curProps = new ArrayList<String>(njc.getJvmOptions());
                final boolean jvmOptionsWereChanged = !oldProps.equals(curProps);
                final List<String> reasons = handle(oldProps, curProps);
                oldProps = curProps;
                // something in the JavaConfig itself changed
                // to do this well, we ought to keep a list of attributes, so we can make a good message
                // saying exactly which attribute what changed
                final Map<String, String> curAttrs = collectAttrs(njc);
                reasons.addAll(handleAttrs(oldAttrs, curAttrs));
                oldAttrs = curAttrs;
                result = reasons.isEmpty() ? null : new NotProcessed(CombinedJavaConfigSystemPropertyListener.toString(reasons));
            } else if (tc == SystemProperty.class && t instanceof SystemProperty) {
                final SystemProperty sp = (SystemProperty) t;
                // check to see if this system property is for this instance
                ConfigBeanProxy proxy = sp.getParent();
                ConfigView p = ConfigSupport.getImpl(proxy);
                if (p == ConfigSupport.getImpl(server) || p == ConfigSupport.getImpl(config) || (cluster != null && p == ConfigSupport.getImpl(cluster)) || p == ConfigSupport.getImpl(domain)) {
                    // check to see if this system property is referenced by any of the options
                    String pname = sp.getName();
                    if (referencesProperty(pname, oldProps) || referencesProperty(pname, oldAttrs.values())) {
                        result = new NotProcessed("The system-property, " + pname + ", that is referenced by the Java configuration, was modified");
                    }
                }
                if (type == TYPE.ADD || type == TYPE.CHANGE) {
                    // create-system-properties
                    if (proxy instanceof Domain) {
                        return addToDomain(sp);
                    } else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
                        return addToConfig(sp);
                    } else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
                        return addToCluster(sp);
                    } else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
                        return addToServer(sp);
                    }
                } else if (type == TYPE.REMOVE) {
                    if (proxy instanceof Domain) {
                        return removeFromDomain(sp);
                    } else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
                        return removeFromConfig(sp);
                    } else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
                        return removeFromCluster(sp);
                    } else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
                        return removeFromServer(sp);
                    }
                }
            } else {
            // ignore other changes that are reported
            }
            return result;
        }
    }, logger);
    return unp;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) Server(com.sun.enterprise.config.serverbeans.Server) TranslatedConfigView(org.glassfish.config.support.TranslatedConfigView) ConfigView(org.jvnet.hk2.config.ConfigView) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) Config(com.sun.enterprise.config.serverbeans.Config) Cluster(com.sun.enterprise.config.serverbeans.Cluster) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Profiler(com.sun.enterprise.config.serverbeans.Profiler) Changed(org.jvnet.hk2.config.Changed) NotProcessed(org.jvnet.hk2.config.NotProcessed) ArrayList(java.util.ArrayList) List(java.util.List) Domain(com.sun.enterprise.config.serverbeans.Domain) TYPE(org.jvnet.hk2.config.Changed.TYPE) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)18 PropertyVetoException (java.beans.PropertyVetoException)5 Domain (com.sun.enterprise.config.serverbeans.Domain)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 Cluster (com.sun.enterprise.config.serverbeans.Cluster)3 Server (com.sun.enterprise.config.serverbeans.Server)3 ActionReport (org.glassfish.api.ActionReport)3 Config (com.sun.enterprise.config.serverbeans.Config)2 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)2 Node (com.sun.enterprise.config.serverbeans.Node)2 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)2 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)2 ArrayList (java.util.ArrayList)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 Test (org.junit.Test)2 Changed (org.jvnet.hk2.config.Changed)2 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)2 NotProcessed (org.jvnet.hk2.config.NotProcessed)2 Property (org.jvnet.hk2.config.types.Property)2 ConfigCustomizationToken (com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken)1