Search in sources :

Example 6 with LogLevel

use of org.apache.storm.generated.LogLevel in project storm by apache.

the class LogConfigManagerTest method ll.

public static LogLevel ll(String target, String reset, long epoc) {
    LogLevel ret = ll();
    ret.set_target_log_level(target);
    ret.set_reset_log_level(reset);
    ret.set_reset_log_level_timeout_epoch(epoc);
    return ret;
}
Also used : LogLevel(org.apache.storm.generated.LogLevel)

Example 7 with LogLevel

use of org.apache.storm.generated.LogLevel in project storm by apache.

the class Nimbus method setLogConfig.

@Override
public void setLogConfig(String topoId, LogConfig config) throws TException {
    try {
        setLogConfigCalls.mark();
        Map<String, Object> topoConf = tryReadTopoConf(topoId, blobStore);
        String topoName = (String) topoConf.get(Config.TOPOLOGY_NAME);
        checkAuthorization(topoName, topoConf, "setLogConfig");
        IStormClusterState state = stormClusterState;
        LogConfig mergedLogConfig = state.topologyLogConfig(topoId, null);
        if (mergedLogConfig == null) {
            mergedLogConfig = new LogConfig();
        }
        Map<String, LogLevel> namedLoggers = mergedLogConfig.get_named_logger_level();
        for (LogLevel level : namedLoggers.values()) {
            level.set_action(LogLevelAction.UNCHANGED);
        }
        if (config.is_set_named_logger_level()) {
            for (Entry<String, LogLevel> entry : config.get_named_logger_level().entrySet()) {
                LogLevel logConfig = entry.getValue();
                String loggerName = entry.getKey();
                LogLevelAction action = logConfig.get_action();
                if (loggerName.isEmpty()) {
                    throw new RuntimeException("Named loggers need a valid name. Use ROOT for the root logger");
                }
                switch(action) {
                    case UPDATE:
                        setLoggerTimeouts(logConfig);
                        mergedLogConfig.put_to_named_logger_level(loggerName, logConfig);
                        break;
                    case REMOVE:
                        Map<String, LogLevel> nl = mergedLogConfig.get_named_logger_level();
                        if (nl != null) {
                            nl.remove(loggerName);
                        }
                        break;
                    default:
                        //NOOP
                        break;
                }
            }
        }
        LOG.info("Setting log config for {}:{}", topoName, mergedLogConfig);
        state.setTopologyLogConfig(topoId, mergedLogConfig);
    } catch (Exception e) {
        LOG.warn("set log config topology exception. (topology id='{}')", topoId, e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) LogLevelAction(org.apache.storm.generated.LogLevelAction) IStormClusterState(org.apache.storm.cluster.IStormClusterState) LogLevel(org.apache.storm.generated.LogLevel) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) InterruptedIOException(java.io.InterruptedIOException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException) LogConfig(org.apache.storm.generated.LogConfig)

Example 8 with LogLevel

use of org.apache.storm.generated.LogLevel in project storm by apache.

the class LogConfigManagerTest method testLogResetTriggersForPastTime.

@Test
public void testLogResetTriggersForPastTime() {
    try (SimulatedTime t = new SimulatedTime()) {
        long past = Time.currentTimeMillis() - 1000;
        TreeMap<String, LogLevel> config = new TreeMap<>();
        config.put("foo", ll("INFO", "WARN", past));
        AtomicReference<TreeMap<String, LogLevel>> atomConf = new AtomicReference<>(config);
        LogConfigManager underTest = new LogConfigManagerUnderTest(atomConf);
        underTest.resetLogLevels();
        assertEquals(new TreeMap<>(), atomConf.get());
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) LogLevel(org.apache.storm.generated.LogLevel) Test(org.junit.Test)

Example 9 with LogLevel

use of org.apache.storm.generated.LogLevel in project storm by apache.

the class LogConfigManagerTest method testLogResetResetsRootLoggerIfSet.

@Test
public void testLogResetResetsRootLoggerIfSet() {
    try (SimulatedTime t = new SimulatedTime()) {
        long past = Time.currentTimeMillis() - 1000;
        TreeMap<String, LogLevel> config = new TreeMap<>();
        config.put(LogManager.ROOT_LOGGER_NAME, ll("DEBUG", "WARN", past));
        AtomicReference<TreeMap<String, LogLevel>> atomConf = new AtomicReference<>(config);
        LogConfigManager underTest = spy(new LogConfigManagerUnderTest(atomConf));
        underTest.resetLogLevels();
        assertEquals(new TreeMap<>(), atomConf.get());
        verify(underTest).setLoggerLevel(anyObject(), eq(LogManager.ROOT_LOGGER_NAME), eq("WARN"));
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) LogLevel(org.apache.storm.generated.LogLevel) Test(org.junit.Test)

Example 10 with LogLevel

use of org.apache.storm.generated.LogLevel in project storm by apache.

the class LogConfigManagerTest method testProcessRootLogLevelToDebugSetsLoggerAndTimeout2.

@Test
public void testProcessRootLogLevelToDebugSetsLoggerAndTimeout2() {
    try (SimulatedTime t = new SimulatedTime()) {
        LogConfig mockConfig = new LogConfig();
        AtomicReference<TreeMap<String, LogLevel>> mockConfigAtom = new AtomicReference<>(null);
        long inThirtySeconds = Time.currentTimeMillis() + 30_000;
        mockConfig.put_to_named_logger_level("ROOT", ll("DEBUG", inThirtySeconds));
        LogConfigManager underTest = spy(new LogConfigManagerUnderTest(mockConfigAtom));
        underTest.processLogConfigChange(mockConfig);
        // test that the set-logger-level function was not called
        LOG.info("Tests {}", mockConfigAtom.get());
        verify(underTest).setLoggerLevel(anyObject(), eq(""), eq("DEBUG"));
        LogLevel rootResult = mockConfigAtom.get().get(LogManager.ROOT_LOGGER_NAME);
        assertNotNull(rootResult);
        assertEquals(LogLevelAction.UPDATE, rootResult.get_action());
        assertEquals("DEBUG", rootResult.get_target_log_level());
        // defaults to INFO level when the logger isn't found previously
        assertEquals("INFO", rootResult.get_reset_log_level());
        assertEquals(inThirtySeconds, rootResult.get_reset_log_level_timeout_epoch());
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) LogLevel(org.apache.storm.generated.LogLevel) LogConfig(org.apache.storm.generated.LogConfig) Test(org.junit.Test)

Aggregations

LogLevel (org.apache.storm.generated.LogLevel)12 TreeMap (java.util.TreeMap)7 Test (org.junit.Test)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)5 Map (java.util.Map)3 LogConfig (org.apache.storm.generated.LogConfig)3 HashMap (java.util.HashMap)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 LogLevelAction (org.apache.storm.generated.LogLevelAction)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 BindException (java.net.BindException)1 TreeSet (java.util.TreeSet)1 IStormClusterState (org.apache.storm.cluster.IStormClusterState)1 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)1 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)1 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)1