Search in sources :

Example 1 with RestMonitoringEndpointDecider

use of fish.payara.appserver.monitoring.rest.service.adapter.RestMonitoringEndpointDecider in project Payara by payara.

the class RestMonitoringService method changed.

@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
    List<UnprocessedChangeEvent> unprocessedChanges = new ArrayList<>();
    boolean dynamicStart = false;
    for (PropertyChangeEvent propertyChangeEvent : propertyChangeEvents) {
        // Check that the property change event is for us.
        if (propertyChangeEvent.getSource().toString().equals("GlassFishConfigBean." + RestMonitoringConfiguration.class.getName()) && isCurrentInstanceMatchTarget(propertyChangeEvent)) {
            // Check if the property has actually changed
            if (!propertyChangeEvent.getOldValue().equals(propertyChangeEvent.getNewValue())) {
                // If the application hasn't attempted to start yet
                if (!startAttempted) {
                    // property, we don't need to compare it to the current value - it can only be true
                    if (propertyChangeEvent.getPropertyName().equals("enabled")) {
                        // Flag that we want to dynamically start Rest Monitoring
                        dynamicStart = true;
                    } else if (propertyChangeEvent.getPropertyName().equals("context-root")) {
                        // If we haven't attempted to start the app yet, grab the new context root
                        Config serverConfig = domain.getServerNamed(serverEnv.getInstanceName()).getConfig();
                        RestMonitoringEndpointDecider endpointDecider = new RestMonitoringEndpointDecider(serverConfig, restMonitoringConfiguration);
                        contextRoot = endpointDecider.getContextRoot();
                    }
                } else if (!propertyChangeEvent.getPropertyName().equals("security-enabled")) {
                    // If a startup has been attempted and the changed property isn't securityEnabled, throw an
                    // unprocessed change event as we need to restart
                    unprocessedChanges.add(new UnprocessedChangeEvent(propertyChangeEvent, "Rest monitoring redeployment required"));
                }
            }
        }
    }
    // This should only be true if rest monitoring was not enabled at startup, and we've just enabled the service
    if (dynamicStart) {
        loadApplication(true);
    }
    // If we need to restart, throw an unprocessed change event
    if (unprocessedChanges.isEmpty()) {
        return null;
    } else {
        return new UnprocessedChangeEvents(unprocessedChanges);
    }
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) RestMonitoringConfiguration(fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration) RestMonitoringEndpointDecider(fish.payara.appserver.monitoring.rest.service.adapter.RestMonitoringEndpointDecider)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)1 RestMonitoringEndpointDecider (fish.payara.appserver.monitoring.rest.service.adapter.RestMonitoringEndpointDecider)1 RestMonitoringConfiguration (fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 ArrayList (java.util.ArrayList)1 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)1 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)1