Search in sources :

Example 1 with JmxControlException

use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.

the class ServerLogWindow method setLoggerLevel.

public void setLoggerLevel() {
    if (StringUtils.isNotEmpty(loggerNameField.<String>getValue())) {
        if (loggerLevelField.getValue() != null) {
            String loggerName = loggerNameField.getValue();
            Level level = loggerLevelField.getValue();
            try {
                jmxRemoteLoggingAPI.setLoggerLevel(getSelectedConnection(), loggerName, level.toString());
            } catch (LogControlException | JmxControlException e) {
                log.error("Error setting logger level", e);
                showNotification(getMessage("exception.logControl"), NotificationType.ERROR);
                return;
            }
            showNotification(formatMessage("logger.setMessage", loggerName, level.toString()), NotificationType.HUMANIZED);
        } else
            showNotification(getMessage("logger.notSelectedLevel"), NotificationType.HUMANIZED);
    } else {
        loggerNameField.setValue(null);
        showNotification(getMessage("logger.notSelected"), NotificationType.HUMANIZED);
    }
}
Also used : Level(ch.qos.logback.classic.Level) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Example 2 with JmxControlException

use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.

the class ServerLogWindow method openAddLoggerDialog.

protected void openAddLoggerDialog() {
    AdditionLoggerWindow additionLogger = (AdditionLoggerWindow) openWindow("serverLogAddLoggerDialog", OpenType.DIALOG);
    additionLogger.addCloseListener(actionId -> {
        if (COMMIT_ACTION_ID.equals(actionId)) {
            Level level = additionLogger.getSelectedLevel();
            String loggerName = additionLogger.getSelectedLoggerName();
            try {
                jmxRemoteLoggingAPI.setLoggerLevel(getSelectedConnection(), loggerName, level.toString());
            } catch (LogControlException | JmxControlException e) {
                log.error("Error setting logger level", e);
                showNotification(getMessage("exception.logControl"), NotificationType.ERROR);
            }
            showNotification(formatMessage("logger.setMessage", loggerName, level.toString()));
            refreshLoggers();
        }
    });
    loggerNameField.setValue(null);
    loggerLevelField.setValue(null);
}
Also used : Level(ch.qos.logback.classic.Level) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Example 3 with JmxControlException

use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.

the class ServerLogWindow method openLoggerControlDialog.

public void openLoggerControlDialog() {
    Map<String, Level> loggersMap = new HashMap<>();
    Map<String, String> loggersLevels = jmxRemoteLoggingAPI.getLoggersLevels(getSelectedConnection());
    for (Map.Entry<String, String> log : loggersLevels.entrySet()) {
        loggersMap.put(log.getKey(), LoggingHelper.getLevelFromString(log.getValue()));
    }
    ControlLoggerWindow controlLogger = (ControlLoggerWindow) openWindow("serverLogLoggerControlDialog", OpenType.DIALOG, ParamsMap.of("loggersMap", loggersMap));
    controlLogger.addCloseListener(actionId -> {
        if (COMMIT_ACTION_ID.equals(actionId)) {
            Map<String, Level> levels = controlLogger.getLevels();
            try {
                Map<String, String> updates = new HashMap<>();
                for (Map.Entry<String, Level> levelEntry : levels.entrySet()) {
                    String loggerName = levelEntry.getKey();
                    Level newLogLevel = levelEntry.getValue();
                    Level prevLevel = loggersMap.get(loggerName);
                    String logLevel = prevLevel == null ? null : prevLevel.toString();
                    if (!Objects.equals(logLevel, newLogLevel.toString())) {
                        updates.put(loggerName, newLogLevel.toString());
                    }
                }
                if (!updates.isEmpty()) {
                    jmxRemoteLoggingAPI.setLoggersLevels(getSelectedConnection(), updates);
                }
            } catch (LogControlException | JmxControlException e) {
                log.error("Error setting logger level", e);
                showNotification(getMessage("exception.logControl"), NotificationType.ERROR);
            }
            showNotification(getMessage("logger.control.apply"), NotificationType.HUMANIZED);
            refreshLoggers();
        }
    });
}
Also used : Level(ch.qos.logback.classic.Level) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) ParamsMap(com.haulmont.bali.util.ParamsMap)

Example 4 with JmxControlException

use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.

the class ServerLogWindow method setAppenderLevel.

public void setAppenderLevel() {
    if (StringUtils.isNotEmpty(appenderNameField.getValue())) {
        if (appenderLevelField.getValue() != null) {
            String appenderName = appenderNameField.getValue();
            Level threshold = appenderLevelField.getValue();
            try {
                jmxRemoteLoggingAPI.setAppenderThreshold(getSelectedConnection(), appenderName, threshold.toString());
            } catch (LogControlException | JmxControlException e) {
                log.error("Error setting appender level", e);
                Throwable rootCause = ExceptionUtils.getRootCause(e);
                showNotification(getMessage("exception.logControl"), rootCause.getMessage(), NotificationType.ERROR);
                return;
            }
            showNotification(formatMessage("appender.setMessage", appenderName, threshold.toString()), NotificationType.HUMANIZED);
        } else
            showNotification(getMessage("appender.notSelectedThreshold"), NotificationType.HUMANIZED);
    } else {
        appenderNameField.setValue(null);
        showNotification(getMessage("appender.notSelected"), NotificationType.HUMANIZED);
    }
}
Also used : Level(ch.qos.logback.classic.Level) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Example 5 with JmxControlException

use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.

the class MbeansDisplayWindow method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    objectNameField.addValueChangeListener(new ObjectNameFieldListener());
    mbeansTable.addAction(new RefreshAction(mbeansTable));
    Action inspectAction = new ItemTrackingAction("inspect").withCaption(getMessage("action.inspect")).withHandler(event -> {
        Set<ManagedBeanInfo> selected = mbeansTable.getSelected();
        if (!selected.isEmpty()) {
            ManagedBeanInfo mbi = selected.iterator().next();
            if (mbi.getObjectName() != null) {
                // otherwise it's a fake root node
                Window editor = openEditor("jmxConsoleInspectMbean", mbi, OpenType.THIS_TAB);
                editor.addCloseListener(actionId -> {
                    mbeansTable.requestFocus();
                });
            } else {
                // expand / collapse fake root node
                UUID itemId = mbi.getId();
                if (mbeansTable.isExpanded(itemId)) {
                    mbeansTable.collapse(itemId);
                } else {
                    mbeansTable.expand(itemId);
                }
            }
        }
    });
    mbeansTable.addAction(inspectAction);
    mbeansTable.setItemClickAction(inspectAction);
    localJmxInstance = jmxControlAPI.getLocalInstance();
    jmxInstancesDs.refresh();
    jmxConnectionField.setValue(localJmxInstance);
    jmxConnectionField.setRequired(true);
    jmxConnectionField.addValueChangeListener(e -> {
        JmxInstance jmxInstance = (JmxInstance) e.getValue();
        try {
            mbeanDs.setJmxInstance(jmxInstance);
            mbeanDs.refresh();
        } catch (JmxControlException ex) {
            showNotification(getMessage("unableToConnectToInterface"), NotificationType.WARNING);
            if (jmxInstance != localJmxInstance) {
                jmxConnectionField.setValue(localJmxInstance);
            }
        }
    });
    jmxConnectionField.removeAllActions();
    jmxConnectionField.addAction(new PickerField.LookupAction(jmxConnectionField) {

        @Override
        public void afterCloseLookup(String actionId) {
            jmxInstancesDs.refresh();
        }
    });
    jmxConnectionField.addAction(new BaseAction("actions.Add").withIcon("icons/plus-btn.png").withHandler(event -> {
        JmxInstanceEditor instanceEditor = (JmxInstanceEditor) openEditor(metadata.create(JmxInstance.class), OpenType.DIALOG);
        instanceEditor.addCloseListener(actionId -> {
            if (COMMIT_ACTION_ID.equals(actionId)) {
                jmxInstancesDs.refresh();
                jmxConnectionField.setValue(instanceEditor.getItem());
            }
        });
    }));
    mbeanDs.setJmxInstance(localJmxInstance);
    mbeanDs.refresh();
    localJmxField.setValue(jmxControlAPI.getLocalNodeName());
    localJmxField.setEditable(false);
    mbeansTable.setStyleProvider((entity, property) -> {
        if (entity != null && entity.getObjectName() == null) {
            return "c-jmx-tree-table-domain";
        }
        return null;
    });
}
Also used : JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) StringUtils(org.apache.commons.lang.StringUtils) RefreshAction(com.haulmont.cuba.gui.components.actions.RefreshAction) ManagedBeanInfoDatasource(com.haulmont.cuba.web.app.ui.jmxcontrol.ds.ManagedBeanInfoDatasource) Resource(javax.annotation.Resource) ParamsMap(com.haulmont.bali.util.ParamsMap) Set(java.util.Set) UUID(java.util.UUID) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) Metadata(com.haulmont.cuba.core.global.Metadata) Inject(javax.inject.Inject) JmxControlAPI(com.haulmont.cuba.web.jmx.JmxControlAPI) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) Map(java.util.Map) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) RefreshAction(com.haulmont.cuba.gui.components.actions.RefreshAction) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) RefreshAction(com.haulmont.cuba.gui.components.actions.RefreshAction) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) UUID(java.util.UUID)

Aggregations

JmxControlException (com.haulmont.cuba.web.jmx.JmxControlException)10 Level (ch.qos.logback.classic.Level)6 LogControlException (com.haulmont.cuba.core.sys.logging.LogControlException)6 ParamsMap (com.haulmont.bali.util.ParamsMap)4 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)3 Metadata (com.haulmont.cuba.core.global.Metadata)3 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)3 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)3 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)3 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 JmxInstanceEditor (com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor)3 JmxControlAPI (com.haulmont.cuba.web.jmx.JmxControlAPI)3 Inject (javax.inject.Inject)3 ManagedBeanAttribute (com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute)2 ManagedBeanInfo (com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo)2 CubaScrollBoxLayout (com.haulmont.cuba.web.toolkit.ui.CubaScrollBoxLayout)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 Map (java.util.Map)2