Search in sources :

Example 6 with ConfigView

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

the class GetHealthCheckConfiguration method addThresholdDiagnosticsCheckerExtraProps.

private void addThresholdDiagnosticsCheckerExtraProps(Properties thresholdDiagnosticsExtraProps, ThresholdDiagnosticsChecker thresholdDiagnosticsChecker) {
    Map<String, Object> extraPropsMap = new HashMap<>(7);
    extraPropsMap.put("checkerName", thresholdDiagnosticsChecker.getName());
    extraPropsMap.put("enabled", thresholdDiagnosticsChecker.getEnabled());
    extraPropsMap.put("time", thresholdDiagnosticsChecker.getTime());
    extraPropsMap.put("unit", thresholdDiagnosticsChecker.getUnit());
    if (thresholdDiagnosticsChecker.getProperty(THRESHOLD_CRITICAL) != null) {
        extraPropsMap.put("thresholdCritical", thresholdDiagnosticsChecker.getProperty(THRESHOLD_CRITICAL).getValue());
    }
    if (thresholdDiagnosticsChecker.getProperty(THRESHOLD_WARNING) != null) {
        extraPropsMap.put("thresholdWarning", thresholdDiagnosticsChecker.getProperty(THRESHOLD_WARNING).getValue());
    }
    if (thresholdDiagnosticsChecker.getProperty(THRESHOLD_GOOD) != null) {
        extraPropsMap.put("thresholdGood", thresholdDiagnosticsChecker.getProperty(THRESHOLD_GOOD).getValue());
    }
    // Get the checker type
    ConfigView view = ConfigSupport.getImpl(thresholdDiagnosticsChecker);
    CheckerConfigurationType annotation = view.getProxyType().getAnnotation(CheckerConfigurationType.class);
    // Add the extraPropsMap as a property with a name matching its checker type
    switch(annotation.type()) {
        case CONNECTION_POOL:
            thresholdDiagnosticsExtraProps.put(connectionPoolPropertyName, extraPropsMap);
            break;
        case CPU_USAGE:
            thresholdDiagnosticsExtraProps.put(cpuUsagePropertyName, extraPropsMap);
            break;
        case GARBAGE_COLLECTOR:
            thresholdDiagnosticsExtraProps.put(garbageCollectorPropertyName, extraPropsMap);
            break;
        case HEAP_MEMORY_USAGE:
            thresholdDiagnosticsExtraProps.put(heapMemoryUsagePropertyName, extraPropsMap);
            break;
        case MACHINE_MEMORY_USAGE:
            thresholdDiagnosticsExtraProps.put(machineMemoryUsagePropertyName, extraPropsMap);
            break;
        case STUCK_THREAD:
            thresholdDiagnosticsExtraProps.put(stuckThreadsPropertyName, extraPropsMap);
            break;
    }
}
Also used : HashMap(java.util.HashMap) ConfigView(org.jvnet.hk2.config.ConfigView) CheckerConfigurationType(fish.payara.nucleus.healthcheck.configuration.CheckerConfigurationType)

Example 7 with ConfigView

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

the class WriteableView method removeNestedElements.

boolean removeNestedElements(Object object) {
    InvocationHandler h = Proxy.getInvocationHandler(object);
    if (!(h instanceof WriteableView)) {
        // h instanceof ConfigView
        ConfigBean bean = (ConfigBean) ((ConfigView) h).getMasterView();
        h = bean.getWriteableView();
        if (h == null) {
            ConfigBeanProxy writable;
            try {
                writable = currentTx.enroll((ConfigBeanProxy) object);
            } catch (TransactionFailure e) {
                // something is seriously wrong
                throw new RuntimeException(e);
            }
            h = Proxy.getInvocationHandler(writable);
        } else {
            // so oldValue was already processed
            return false;
        }
    }
    WriteableView writableView = (WriteableView) h;
    synchronized (writableView) {
        writableView.isDeleted = true;
    }
    boolean removed = false;
    for (Property property : writableView.bean.model.elements.values()) {
        if (property.isCollection()) {
            Object nested = writableView.getter(property, parameterizedType);
            ProtectedList list = (ProtectedList) nested;
            if (list.size() > 0) {
                list.clear();
                removed = true;
            }
        } else if (!property.isLeaf()) {
            // Element
            Object oldValue = writableView.getter(property, ConfigBeanProxy.class);
            if (oldValue != null) {
                writableView.setter(property, null, Dom.class);
                removed = true;
                removeNestedElements(oldValue);
            }
        }
    }
    return removed;
}
Also used : InvocationHandler(java.lang.reflect.InvocationHandler) Property(org.jvnet.hk2.config.ConfigModel.Property)

Example 8 with ConfigView

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

the class GetNotificationConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    ActionReport mainActionReport = context.getActionReport();
    final NotificationServiceConfiguration notificationServiceConfiguration = config.getExtensionByType(NotificationServiceConfiguration.class);
    NotificationServiceConfiguration configuration = config.getExtensionByType(NotificationServiceConfiguration.class);
    List<ServiceHandle<BaseNotifierService>> allServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
    String[] headers = { "Enabled", "Notifier Enabled" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    if (configuration.getNotifierConfigurationList().isEmpty()) {
        mainActionReport.setMessage("No notifier defined");
    } else {
        List<Class<NotifierConfiguration>> notifierConfigurationClassList = Lists.transform(configuration.getNotifierConfigurationList(), new Function<NotifierConfiguration, Class<NotifierConfiguration>>() {

            @Override
            public Class<NotifierConfiguration> apply(NotifierConfiguration input) {
                return resolveNotifierConfigurationClass(input);
            }
        });
        Properties extraProps = new Properties();
        for (ServiceHandle<BaseNotifierService> serviceHandle : allServiceHandles) {
            NotifierConfiguration notifierConfiguration = configuration.getNotifierConfigurationByType(serviceHandle.getService().getNotifierConfigType());
            if (notifierConfiguration != null) {
                ConfigView view = ConfigSupport.getImpl(notifierConfiguration);
                NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
                if (notifierConfigurationClassList.contains(view.<NotifierConfiguration>getProxyType())) {
                    Object[] values = new Object[2];
                    values[0] = notificationServiceConfiguration.getEnabled();
                    values[1] = notifierConfiguration.getEnabled();
                    columnFormatter.addRow(values);
                    Map<String, Object> map;
                    if (NotifierType.LOG.equals(annotation.type())) {
                        map = new HashMap<>(3);
                        map.put("enabled", values[0]);
                        map.put("notifierEnabled", values[1]);
                        LogNotifierConfiguration logNotifierConfiguration = (LogNotifierConfiguration) notifierConfiguration;
                        map.put("useSeparateLogFile", logNotifierConfiguration.getUseSeparateLogFile());
                    } else {
                        map = new HashMap<>(2);
                        map.put("enabled", values[0]);
                        map.put("notifierEnabled", values[1]);
                    }
                    extraProps.put("getNotificationConfiguration" + annotation.type(), map);
                }
            }
        }
        mainActionReport.setExtraProperties(extraProps);
        mainActionReport.setMessage(columnFormatter.toString());
    }
    mainActionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) NotifierConfiguration(fish.payara.nucleus.notification.configuration.NotifierConfiguration) LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) LogNotifierConfiguration(fish.payara.nucleus.notification.log.LogNotifierConfiguration) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) NotificationServiceConfiguration(fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 9 with ConfigView

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

ConfigView (org.jvnet.hk2.config.ConfigView)7 Config (com.sun.enterprise.config.serverbeans.Config)5 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)5 HashMap (java.util.HashMap)5 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)4 Notifier (fish.payara.nucleus.notification.configuration.Notifier)4 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)4 Properties (java.util.Properties)4 ActionReport (org.glassfish.api.ActionReport)4 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)2 Property (org.jvnet.hk2.config.types.Property)2 HasCustomizationTokens (com.sun.enterprise.config.modularity.annotation.HasCustomizationTokens)1 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)1 Profiler (com.sun.enterprise.config.serverbeans.Profiler)1 Server (com.sun.enterprise.config.serverbeans.Server)1