Search in sources :

Example 1 with ConfigView

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

the class MonitoringService method bootstrapNotifierList.

/**
 * Starts notifiers that are enabled with the monitoring service
 * @since 4.1.2.174
 */
public void bootstrapNotifierList() {
    notifierExecutionOptionsList = new ArrayList<>();
    if (configuration.getNotifierList() != null) {
        for (Notifier notifier : configuration.getNotifierList()) {
            ConfigView view = ConfigSupport.getImpl(notifier);
            NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
            notifierExecutionOptionsList.add(executionOptionsFactoryStore.get(annotation.type()).build(notifier));
        }
    }
    if (notifierExecutionOptionsList.isEmpty()) {
        // Add logging execution options by default
        LogNotifierExecutionOptions logNotifierExecutionOptions = new LogNotifierExecutionOptions();
        logNotifierExecutionOptions.setEnabled(true);
        notifierExecutionOptionsList.add(logNotifierExecutionOptions);
    }
}
Also used : NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) ConfigView(org.jvnet.hk2.config.ConfigView) Notifier(fish.payara.nucleus.notification.configuration.Notifier) LogNotifierExecutionOptions(fish.payara.nucleus.notification.log.LogNotifierExecutionOptions)

Example 2 with ConfigView

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

the class GetMonitoringConfiguration method execute.

/**
 * Method that is invoked when the asadmin command is performed.
 *  Pretty prints the Monitoring Service Configuration values.
 * @param context
 */
@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config name: " + targetUtil);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    ActionReport actionReport = context.getActionReport();
    ActionReport notifiersReport = actionReport.addSubActionsReport();
    ActionReport attributeReport = actionReport.addSubActionsReport();
    ColumnFormatter attributeColumnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
    ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
    MonitoringServiceConfiguration monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
    List<ServiceHandle<BaseNotifierService>> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
    actionReport.appendMessage("Monitoring Service Configuration is enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getEnabled())) + "\n");
    actionReport.appendMessage("Monitoring Service Configuration has AMX enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getAmx())) + "\n");
    actionReport.appendMessage("Monitoring Service Configuration log frequency? " + monitoringConfig.getLogFrequency() + " " + monitoringConfig.getLogFrequencyUnit());
    actionReport.appendMessage(StringUtils.EOL);
    Map<String, Object> map = new HashMap<>();
    Properties extraProps = new Properties();
    map.put("enabled", monitoringConfig.getEnabled());
    map.put("amx", monitoringConfig.getAmx());
    map.put("logfrequency", monitoringConfig.getLogFrequency());
    map.put("logfrequencyunit", monitoringConfig.getLogFrequencyUnit());
    extraProps.put("jmxmonitoringConfiguration", map);
    List<Map<String, String>> monitoredAttributes = new ArrayList<>();
    for (MonitoredAttribute monitoredBean : monitoringConfig.getMonitoredAttributes()) {
        Object[] values = new Object[3];
        values[0] = monitoredBean.getObjectName();
        values[1] = monitoredBean.getAttributeName();
        values[2] = monitoredBean.getDescription();
        Map<String, String> monitoredAttribute = new HashMap<>();
        monitoredAttribute.put(monitoredBean.getObjectName(), monitoredBean.getAttributeName());
        monitoredAttributes.add(monitoredAttribute);
        attributeColumnFormatter.addRow(values);
    }
    // Cannot change key in line below - required for admingui propertyDescTable.inc
    extraProps.put("monitored-beans", monitoredAttributes);
    actionReport.setExtraProperties(extraProps);
    if (!monitoringConfig.getNotifierList().isEmpty()) {
        List<Class<Notifier>> notifierClassList = Lists.transform(monitoringConfig.getNotifierList(), new Function<Notifier, Class<Notifier>>() {

            @Override
            public Class<Notifier> apply(Notifier input) {
                return resolveNotifierClass(input);
            }
        });
        Properties notifierProps = new Properties();
        for (ServiceHandle<BaseNotifierService> serviceHandle : allNotifierServiceHandles) {
            Notifier notifier = monitoringConfig.getNotifierByType(serviceHandle.getService().getNotifierType());
            if (notifier != null) {
                ConfigView view = ConfigSupport.getImpl(notifier);
                NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
                if (notifierClassList.contains(view.<Notifier>getProxyType())) {
                    Object[] values = new Object[2];
                    values[0] = annotation.type();
                    values[1] = notifier.getEnabled();
                    notifiersColumnFormatter.addRow(values);
                    Map<String, Object> mapNotifiers = new HashMap<>(2);
                    mapNotifiers.put("notifierName", values[0]);
                    mapNotifiers.put("notifierEnabled", values[1]);
                    notifierProps.put("notifierList" + annotation.type(), mapNotifiers);
                }
            }
            actionReport.getExtraProperties().putAll(notifierProps);
        }
    }
    notifiersReport.setMessage(notifiersColumnFormatter.toString());
    notifiersReport.appendMessage(StringUtils.EOL);
    attributeReport.setMessage(attributeColumnFormatter.toString());
    attributeReport.appendMessage(StringUtils.EOL);
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : MonitoredAttribute(fish.payara.jmx.monitoring.configuration.MonitoredAttribute) HashMap(java.util.HashMap) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) Notifier(fish.payara.nucleus.notification.configuration.Notifier) NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ConfigView

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

the class ConfigModularityUtils method setConfigBean.

public <T extends ConfigBeanProxy> T setConfigBean(T finalConfigBean, ConfigBeanDefaultValue configBeanDefaultValue, ConfigBeanProxy parent) {
    Class owningClassForLocation = getOwningClassForLocation(configBeanDefaultValue.getLocation());
    Class configBeanClass = getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());
    try {
        ConfigBeanProxy configBeanInstance = null;
        if (getNameForConfigBean(finalConfigBean, configBeanClass) == null) {
            List<ConfigBeanProxy> extensions = getExtensions(parent);
            for (ConfigBeanProxy extension : extensions) {
                try {
                    configBeanInstance = (ConfigBeanProxy) configBeanClass.cast(extension);
                    break;
                } catch (Exception e) {
                // ignore, not the right type.
                }
            }
            if (!configBeanDefaultValue.replaceCurrentIfExists() || !stackPositionHigher(finalConfigBean, configBeanInstance)) {
                if (configBeanInstance != null)
                    return (T) configBeanInstance;
            }
            if (configBeanInstance != null) {
                extensions.remove(configBeanInstance);
            }
        }
    } catch (InvocationTargetException e) {
        LOG.log(Level.INFO, cannotSetConfigBean, e);
    } catch (IllegalAccessException e) {
        LOG.log(Level.INFO, cannotSetConfigBean, e);
    }
    Method m = getMatchingSetterMethod(owningClassForLocation, configBeanClass);
    if (m != null) {
        try {
            if (configBeanClass.getAnnotation(HasCustomizationTokens.class) != null) {
                applyCustomTokens(configBeanDefaultValue, finalConfigBean, parent);
            }
            m.invoke(parent, finalConfigBean);
        } catch (Exception e) {
            LogHelper.log(LOG, Level.INFO, cannotSetConfigBeanFor, e, finalConfigBean.getClass().getName());
        }
        return finalConfigBean;
    }
    m = findSuitableCollectionGetter(owningClassForLocation, configBeanClass);
    if (m != null) {
        try {
            Collection col = (Collection) m.invoke(parent);
            String name = getNameForConfigBean(finalConfigBean, configBeanClass);
            ConfigBeanProxy itemToRemove = getNamedConfigBeanFromCollection(col, name, configBeanClass);
            if (configBeanDefaultValue.replaceCurrentIfExists()) {
                try {
                    if (itemToRemove != null) {
                        if (stackPositionHigher(finalConfigBean, itemToRemove)) {
                            col.remove(itemToRemove);
                        }
                    }
                } catch (Exception ex) {
                    LogHelper.log(LOG, Level.INFO, cannotRemoveConfigBean, ex, finalConfigBean.getClass().getName());
                }
            }
            if (configBeanClass.getAnnotation(HasCustomizationTokens.class) != null) {
                applyCustomTokens(configBeanDefaultValue, finalConfigBean, parent);
            }
            if (itemToRemove != null && !configBeanDefaultValue.replaceCurrentIfExists()) {
                // Check for duplication here.
                if (((ConfigView) Proxy.getInvocationHandler(itemToRemove)).getProxyType().isAssignableFrom(configBeanClass)) {
                    return finalConfigBean;
                }
            }
            col.add(finalConfigBean);
            return finalConfigBean;
        } catch (Exception e) {
            LogHelper.log(LOG, Level.INFO, cannotSetConfigBeanFor, e, finalConfigBean.getClass().getName());
        }
    }
    return null;
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Collection(java.util.Collection) Method(java.lang.reflect.Method) HasCustomizationTokens(com.sun.enterprise.config.modularity.annotation.HasCustomizationTokens) PropertyVetoException(java.beans.PropertyVetoException) XMLStreamException(javax.xml.stream.XMLStreamException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 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 : Property(org.jvnet.hk2.config.ConfigModel.Property)

Example 5 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<>(8);
    extraPropsMap.put("checkerName", thresholdDiagnosticsChecker.getName());
    extraPropsMap.put("enabled", thresholdDiagnosticsChecker.getEnabled());
    extraPropsMap.put("time", thresholdDiagnosticsChecker.getTime());
    extraPropsMap.put("unit", thresholdDiagnosticsChecker.getUnit());
    extraPropsMap.put("addToMicroProfileHealth", thresholdDiagnosticsChecker.getAddToMicroProfileHealth());
    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)

Aggregations

ConfigView (org.jvnet.hk2.config.ConfigView)4 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)3 Config (com.sun.enterprise.config.serverbeans.Config)2 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)2 Notifier (fish.payara.nucleus.notification.configuration.Notifier)2 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 ActionReport (org.glassfish.api.ActionReport)2 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)2 HasCustomizationTokens (com.sun.enterprise.config.modularity.annotation.HasCustomizationTokens)1 MonitoredAttribute (fish.payara.jmx.monitoring.configuration.MonitoredAttribute)1 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)1 CheckerConfigurationType (fish.payara.nucleus.healthcheck.configuration.CheckerConfigurationType)1 NotificationServiceConfiguration (fish.payara.nucleus.notification.configuration.NotificationServiceConfiguration)1 NotifierConfiguration (fish.payara.nucleus.notification.configuration.NotifierConfiguration)1 LogNotifierConfiguration (fish.payara.nucleus.notification.log.LogNotifierConfiguration)1 LogNotifierExecutionOptions (fish.payara.nucleus.notification.log.LogNotifierExecutionOptions)1 PropertyVetoException (java.beans.PropertyVetoException)1 IOException (java.io.IOException)1