Search in sources :

Example 6 with UnprocessedChangeEvent

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

the class AutoDeployService method changed.

@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    if (autoDeployer == null) {
        return null;
    }
    /* Record any events we tried to process but could not. */
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    Boolean newEnabled = null;
    Integer newPollingIntervalInSeconds = null;
    for (PropertyChangeEvent event : events) {
        if (event.getSource() instanceof DasConfig) {
            String propName = event.getPropertyName();
            if (configPropertyNames.contains(propName) && event.getOldValue().equals(event.getNewValue())) {
                deplLogger.fine("[AutoDeploy] Ignoring reconfig of " + propName + " from " + event.getOldValue() + " to " + event.getNewValue());
                continue;
            }
            /*
                 * Substitute any placeholders in the new and old values.
                 */
            final String oldValue = replaceTokens((String) event.getOldValue(), System.getProperties());
            final String newValue = replaceTokens((String) event.getNewValue(), System.getProperties());
            if (propName.equals("autodeploy-enabled")) {
                /*
                     * Either start the currently stopped autodeployer or stop the
                     * currently running one.
                     */
                newEnabled = Boolean.valueOf(newValue);
                deplLogger.fine("[AutoDeploy] Reconfig - enabled changed to " + newEnabled);
            } else if (propName.equals("autodeploy-polling-interval-in-seconds")) {
                try {
                    newPollingIntervalInSeconds = new Integer(newValue);
                    deplLogger.fine("[AutoDeploy] Reconfig - polling interval (seconds) changed from " + oldValue + " to " + newPollingIntervalInSeconds);
                } catch (NumberFormatException ex) {
                    deplLogger.log(Level.WARNING, CONFIGURATION_CHANGE_ERROR, new Object[] { propName, oldValue, newValue, ex.getClass().getName(), ex.getLocalizedMessage() });
                }
            } else if (propName.equals("autodeploy-dir")) {
                String newDir = newValue;
                try {
                    autoDeployer.setDirectory(newDir);
                    deplLogger.fine("[AutoDeploy] Reconfig - directory changed from " + oldValue + " to " + newDir);
                } catch (AutoDeploymentException ex) {
                    deplLogger.log(Level.WARNING, CONFIGURATION_CHANGE_ERROR, new Object[] { propName, oldValue, newValue, ex.getClass().getName(), ex.getLocalizedMessage() });
                }
            } else if (propName.equals("autodeploy-verifier-enabled")) {
                boolean newVerifierEnabled = Boolean.parseBoolean(newValue);
                autoDeployer.setVerifierEnabled(newVerifierEnabled);
                deplLogger.fine("[AutoDeploy] Reconfig - verifierEnabled changed from " + Boolean.parseBoolean(oldValue) + " to " + newVerifierEnabled);
            } else if (propName.equals("autodeploy-jsp-precompilation-enabled")) {
                boolean newJspPrecompiled = Boolean.parseBoolean(newValue);
                autoDeployer.setJspPrecompilationEnabled(newJspPrecompiled);
                deplLogger.fine("[AutoDeploy] Reconfig - jspPrecompilationEnabled changed from " + Boolean.parseBoolean(oldValue) + " to " + newJspPrecompiled);
            }
        }
    }
    if (newEnabled != null) {
        if (newEnabled) {
            startAutoDeployer(newPollingIntervalInSeconds == null ? getPollingIntervalInSeconds() : newPollingIntervalInSeconds);
        } else {
            stopAutoDeployer();
        }
    } else {
        if ((newPollingIntervalInSeconds != null) && isAutoDeployEnabled()) {
            /*
                 * There is no change in whether the autodeployer should be running, only
                 * in how often it should run.  If it is not running now don't
                 * start it.  If it is running now, restart it to use the new
                 * polling interval.
                 */
            rescheduleAutoDeployer(newPollingIntervalInSeconds);
        }
    }
    return (unprocessedEvents.size() > 0) ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) DasConfig(com.sun.enterprise.config.serverbeans.DasConfig)

Example 7 with UnprocessedChangeEvent

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

the class RemoveLibraryCommand method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    File libDir = env.getLibPath();
    if (type.equals("ext")) {
        libDir = new File(libDir, "ext");
    } else if (type.equals("app")) {
        libDir = new File(libDir, "applibs");
    }
    try {
        List<UnprocessedChangeEvent> unprocessed = new ArrayList<UnprocessedChangeEvent>();
        // delete the file from the appropriate library directory
        StringBuilder msg = new StringBuilder();
        for (String libraryName : names) {
            File libraryFile = new File(libDir, libraryName);
            if (libraryFile.exists()) {
                boolean isDeleted = FileUtils.deleteFile(libraryFile);
                if (!isDeleted) {
                    msg.append(localStrings.getLocalString("lfnd", "Could not remove library file", libraryFile.getAbsolutePath()));
                } else {
                    PropertyChangeEvent pe = new PropertyChangeEvent(libDir, "remove-library", libraryFile, null);
                    UnprocessedChangeEvent uce = new UnprocessedChangeEvent(pe, "remove-library");
                    unprocessed.add(uce);
                }
            } else {
                msg.append(localStrings.getLocalString("lfnf", "Library file not found", libraryFile.getAbsolutePath()));
            }
        }
        if (msg.length() > 0) {
            logger.log(Level.WARNING, msg.toString());
            report.setActionExitCode(ActionReport.ExitCode.WARNING);
            report.setMessage(msg.toString());
        }
        // set the restart required flag
        UnprocessedChangeEvents uces = new UnprocessedChangeEvents(unprocessed);
        List<UnprocessedChangeEvents> ucesList = new ArrayList<UnprocessedChangeEvents>();
        ucesList.add(uces);
        ucl.unprocessedTransactedEvents(ucesList);
        // touch the domain.xml so instances restart will synch
        // over the libraries.
        dxp.touch();
    } catch (Exception e) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(e.getMessage());
    }
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) File(java.io.File)

Example 8 with UnprocessedChangeEvent

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

the class JMSConfigListener method changed.

/**
 * Implementation of org.jvnet.hk2.config.ConfigListener
 */
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    // Events that we can't process now because they require server restart.
    jmsService = serverConfig.getExtensionByType(JmsService.class);
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "In JMSConfigListener - received config event");
    }
    Domain domain = Globals.get(Domain.class);
    String jmsProviderPort = null;
    ServerContext serverContext = Globals.get(ServerContext.class);
    Server thisServer = domain.getServerNamed(serverContext.getInstanceName());
    // if(thisServer.isDas() || thisServer.getCluster() == null)
    {
    // _logger.log(Level.FINE,"JMSConfigListerner server is either das or a stand-alone instance - hence ignoring");
    // return null;
    }
    for (int i = 0; i < events.length; i++) {
        // for (PropertyChangeEvent event : events) {
        PropertyChangeEvent event = events[i];
        String eventName = event.getPropertyName();
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "In JMSConfigListener " + eventName + oldValue + newValue);
        }
        if (oldValue != null && oldValue.equals(newValue)) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Event " + eventName + " did not change existing value of " + oldValue);
            }
            continue;
        }
        if (event.getSource().toString().indexOf("connectors.jms.config.JmsService") != -1) {
            boolean notifyFlag = true;
            if (oldValue != null && newValue == null && "jms-host".equals(event.getPropertyName())) {
                JmsHost jmsHost = (JmsHost) oldValue;
                String name = ActiveJmsResourceAdapter.GRIZZLY_PROXY_PREFIX + jmsHost.getName();
                ActiveJmsResourceAdapter adapter = Globals.get(ActiveJmsResourceAdapter.class);
                if (adapter.getGrizzlyListeners().contains(name)) {
                    GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
                    synchronized (adapter.getGrizzlyListeners()) {
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, "Stopping Grizzly proxy " + name);
                        }
                        grizzlyService.removeNetworkProxy(name);
                        adapter.getGrizzlyListeners().remove(name);
                    }
                    notifyFlag = false;
                }
            }
            if (notifyFlag) {
                UnprocessedChangeEvent uchangeEvent = new UnprocessedChangeEvent(event, "restart required");
                unprocessedEvents.add(uchangeEvent);
            }
        } else if (event.getSource().toString().indexOf("connectors.jms.config.JmsHost") != -1) {
            if (oldValue == null && newValue != null && "name".equals(event.getPropertyName())) {
                JmsProviderLifecycle lifecycle = Globals.get(JmsProviderLifecycle.class);
                JmsHost jmsHost = (JmsHost) event.getSource();
                if (ActiveJmsResourceAdapter.EMBEDDED.equalsIgnoreCase(jmsService.getType())) {
                    ActiveJmsResourceAdapter adapter = Globals.get(ActiveJmsResourceAdapter.class);
                    if (!adapter.getDoBind()) {
                        if (Boolean.valueOf(jmsHost.getLazyInit())) {
                            String host = null;
                            if (jmsHost.getHost() != null && "localhost".equals(jmsHost.getHost())) {
                                host = "0.0.0.0";
                            } else {
                                host = jmsHost.getHost();
                            }
                            try {
                                GrizzlyService grizzlyService = Globals.get(GrizzlyService.class);
                                NetworkListener dummy = new DummyNetworkListener();
                                dummy.setPort(jmsHost.getPort());
                                dummy.setAddress(host);
                                dummy.setType("proxy");
                                dummy.setProtocol(ActiveJmsResourceAdapter.JMS_SERVICE);
                                dummy.setTransport("tcp");
                                String name = ActiveJmsResourceAdapter.GRIZZLY_PROXY_PREFIX + jmsHost.getName();
                                dummy.setName(name);
                                synchronized (adapter.getGrizzlyListeners()) {
                                    if (_logger.isLoggable(Level.FINE)) {
                                        _logger.log(Level.FINE, "Starting Grizzly proxy " + name + " on port " + jmsHost.getPort());
                                    }
                                    grizzlyService.createNetworkProxy(dummy);
                                    adapter.getGrizzlyListeners().add(name);
                                }
                                return unprocessedEvents.size() > 0 ? new UnprocessedChangeEvents(unprocessedEvents) : null;
                            } catch (Exception e) {
                                LogHelper.log(_logger, Level.WARNING, JMSLoggerInfo.GRIZZLY_START_FAILURE, e);
                            }
                        }
                    }
                }
            }
        }
        if ("JMS_PROVIDER_PORT".equals(newValue)) {
            // The value is in the next event
            PropertyChangeEvent nextevent = events[i + 1];
            jmsProviderPort = (String) nextevent.getNewValue();
        }
        if (event.getSource() instanceof JmsService) {
            if (eventName.equals(ServerTags.MASTER_BROKER)) {
                String oldMB = oldValue != null ? oldValue.toString() : null;
                String newMB = newValue != null ? newValue.toString() : null;
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Got JmsService Master Broker change event " + event.getSource() + " " + eventName + " " + oldMB + " " + newMB);
                }
                if (newMB != null) {
                    Server newMBServer = domain.getServerNamed(newMB);
                    if (newMBServer != null) {
                        Node node = domain.getNodeNamed(newMBServer.getNodeRef());
                        String newMasterBrokerPort = JmsRaUtil.getJMSPropertyValue(newMBServer);
                        if (newMasterBrokerPort == null)
                            newMasterBrokerPort = getDefaultJmsHost(jmsService).getPort();
                        String newMasterBrokerHost = node.getNodeHost();
                        aresourceAdapter.setMasterBroker(newMasterBrokerHost + ":" + newMasterBrokerPort);
                    }
                }
            }
        }
        if (eventName.equals(ServerTags.SERVER_REF)) {
            // if(event instanceof ServerRef){
            String oldServerRef = oldValue != null ? oldValue.toString() : null;
            String newServerRef = newValue != null ? newValue.toString() : null;
            if (oldServerRef != null && newServerRef == null && !thisServer.isDas()) {
                // instance has been deleted
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Got Cluster change event for server_ref" + event.getSource() + " " + eventName + " " + oldServerRef + " " + null);
                }
                String url = getBrokerList();
                aresourceAdapter.setClusterBrokerList(url);
                break;
            }
        // 
        }
        // else skip
        if (event.getSource() instanceof Server) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "In JMSConfigListener - recieved cluster event " + event.getSource());
            }
            Server changedServer = (Server) event.getSource();
            if (thisServer.isDas())
                return null;
            if (jmsProviderPort != null) {
                String nodeName = changedServer.getNodeRef();
                String nodeHost = null;
                if (nodeName != null)
                    nodeHost = domain.getNodeNamed(nodeName).getNodeHost();
                String url = getBrokerList();
                url = url + ",mq://" + nodeHost + ":" + jmsProviderPort;
                aresourceAdapter.setClusterBrokerList(url);
                break;
            }
        }
    }
    return unprocessedEvents.size() > 0 ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) JmsService(com.sun.enterprise.connectors.jms.config.JmsService) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ServerContext(org.glassfish.internal.api.ServerContext) GrizzlyService(com.sun.enterprise.v3.services.impl.GrizzlyService) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) DummyNetworkListener(com.sun.enterprise.v3.services.impl.DummyNetworkListener) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 9 with UnprocessedChangeEvent

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

the class TransactionServiceConfigListener method changed.

/**
 *************************************************************************
 */
/**
 * Implementation of org.jvnet.hk2.config.ConfigListener ********************
 */
/**
 *************************************************************************
 */
@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    // Events that we can't process now because they require server restart.
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    for (PropertyChangeEvent event : events) {
        String eventName = event.getPropertyName();
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        boolean accepted = true;
        _logger.log(Level.FINE, "Got TransactionService change event ==== {0} {1} {2} {3}", new Object[] { event.getSource(), eventName, oldValue, newValue });
        if (oldValue != null && oldValue.equals(newValue)) {
            _logger.log(Level.FINE, "Event {0} did not change existing value of {1}", new Object[] { eventName, oldValue });
            continue;
        }
        if (event.getSource() instanceof ModuleMonitoringLevels) {
            if (eventName.equals(ServerTags.TRANSACTION_SERVICE)) {
                String newlevel = newValue.toString();
                _logger.log(Level.FINE, "Changing transaction monitoring level");
                if ("OFF".equals(newlevel)) {
                    tm.setMonitoringEnabled(false);
                } else if ("LOW".equals(newlevel) || "HIGH".equals(newlevel)) {
                    tm.setMonitoringEnabled(true);
                }
            }
        // else skip
        } else if (eventName.equals(ServerTags.TIMEOUT_IN_SECONDS)) {
            try {
                tm.setDefaultTransactionTimeout(Integer.parseInt((String) newValue, 10));
                _logger.log(Level.FINE, " Transaction Timeout interval event processed for: {0}", newValue);
            } catch (Exception ex) {
                _logger.log(Level.WARNING, "transaction.reconfig_txn_timeout_failed", ex);
            }
        // timeout-in-seconds
        } else if (eventName.equals(ServerTags.KEYPOINT_INTERVAL) || eventName.equals(ServerTags.RETRY_TIMEOUT_IN_SECONDS)) {
            tm.handlePropertyUpdate(eventName, newValue);
            _logger.log(Level.FINE, "{0} reconfig event processed for new value: {1}", new Object[] { eventName, newValue });
        } else if (event.getPropertyName().equals("value")) {
            eventName = ((Property) event.getSource()).getName();
            _logger.log(Level.FINE, "Got Property change event for {0}", eventName);
            if (eventName.equals("purge-cancelled-transactions-after")) {
                String v = (String) newValue;
                if (v == null || v.length() == 0) {
                    tm.setPurgeCancelledTtransactionsAfter(0);
                } else {
                    tm.setPurgeCancelledTtransactionsAfter(Integer.parseInt(v, 10));
                }
            } else {
                // Not handled dynamically. Restart is required.
                accepted = false;
            }
        } else if (event.getPropertyName().equals("name") || event.getPropertyName().equals("property")) {
            // skip - means a new property added, was processed above as "value".
            _logger.log(Level.FINE, "...skipped");
        } else {
            // Not handled dynamically. Restart is required.
            accepted = false;
        }
        if (!accepted) {
            String msg = sm.getString("enterprise_distributedtx.restart_required", eventName);
            _logger.log(Level.INFO, msg);
            unprocessedEvents.add(new UnprocessedChangeEvent(event, msg));
        }
    }
    return (unprocessedEvents.size() > 0) ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) ModuleMonitoringLevels(com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) Property(org.jvnet.hk2.config.types.Property)

Example 10 with UnprocessedChangeEvent

use of org.jvnet.hk2.config.UnprocessedChangeEvent 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)

Aggregations

UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)14 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)14 PropertyChangeEvent (java.beans.PropertyChangeEvent)12 ArrayList (java.util.ArrayList)11 ActionReport (org.glassfish.api.ActionReport)4 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)3 Config (com.sun.enterprise.config.serverbeans.Config)2 DasConfig (com.sun.enterprise.config.serverbeans.DasConfig)2 PropertyVetoException (java.beans.PropertyVetoException)2 File (java.io.File)2 Logger (java.util.logging.Logger)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 ModuleMonitoringLevels (com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels)1 JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)1 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)1 CurrentBeforeParentClassLoader (com.sun.enterprise.loader.CurrentBeforeParentClassLoader)1 DummyNetworkListener (com.sun.enterprise.v3.services.impl.DummyNetworkListener)1 GrizzlyService (com.sun.enterprise.v3.services.impl.GrizzlyService)1 RestMonitoringEndpointDecider (fish.payara.appserver.monitoring.rest.service.adapter.RestMonitoringEndpointDecider)1 RestMonitoringConfiguration (fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration)1