Search in sources :

Example 1 with LogConfig

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

the class UIHelpers method putTopologyLogLevel.

/**
 * putTopologyLogLevel.
 * @param client client
 * @param namedLogLevel namedLogLevel
 * @param id id
 * @return putTopologyLogLevel.
 * @throws TException TException
 */
public static Map<String, Object> putTopologyLogLevel(Nimbus.Iface client, Map<String, Map> namedLogLevel, String id) throws TException {
    Map<String, Map> namedLoggerlevels = namedLogLevel;
    for (Map.Entry<String, Map> entry : namedLoggerlevels.entrySet()) {
        String loggerNMame = entry.getKey();
        String targetLevel = (String) entry.getValue().get("target_level");
        Long timeout = (Long) entry.getValue().get("timeout");
        LogLevel logLevel = new LogLevel();
        if (targetLevel == null) {
            logLevel.set_action(LogLevelAction.REMOVE);
            logLevel.unset_target_log_level();
        } else {
            logLevel.set_action(LogLevelAction.UPDATE);
            logLevel.set_target_log_level(org.apache.logging.log4j.Level.toLevel(targetLevel).name());
            logLevel.set_reset_log_level_timeout_secs(Math.toIntExact(timeout));
        }
        LogConfig logConfig = new LogConfig();
        logConfig.put_to_named_logger_level(loggerNMame, logLevel);
        client.setLogConfig(id, logConfig);
    }
    return UIHelpers.getTopolgoyLogConfig(client.getLogConfig(id));
}
Also used : Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) LogLevel(org.apache.storm.generated.LogLevel) LogConfig(org.apache.storm.generated.LogConfig)

Example 2 with LogConfig

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

the class SetLogLevel method main.

public static void main(String[] args) throws Exception {
    Map<String, Object> cl = CLI.opt("l", "log-setting", null, new LogLevelsParser(LogLevelAction.UPDATE), CLI.INTO_MAP).opt("r", "remove-log-setting", null, new LogLevelsParser(LogLevelAction.REMOVE), CLI.INTO_MAP).arg("topologyName", CLI.FIRST_WINS).parse(args);
    final String topologyName = (String) cl.get("topologyName");
    Utils.validateTopologyName(topologyName);
    final LogConfig logConfig = new LogConfig();
    Map<String, LogLevel> logLevelMap = new HashMap<>();
    Map<String, LogLevel> updateLogLevel = (Map<String, LogLevel>) cl.get("l");
    if (null != updateLogLevel) {
        logLevelMap.putAll(updateLogLevel);
    }
    Map<String, LogLevel> removeLogLevel = (Map<String, LogLevel>) cl.get("r");
    if (null != removeLogLevel) {
        logLevelMap.putAll(removeLogLevel);
    }
    for (Map.Entry<String, LogLevel> entry : logLevelMap.entrySet()) {
        logConfig.put_to_named_logger_level(entry.getKey(), entry.getValue());
    }
    NimbusClient.withConfiguredClient(new NimbusClient.WithNimbus() {

        @Override
        public void run(Nimbus.Iface nimbus) throws Exception {
            String topologyId = Utils.getTopologyId(topologyName, nimbus);
            if (null == topologyId) {
                throw new IllegalArgumentException(topologyName + " is not a running topology");
            }
            nimbus.setLogConfig(topologyId, logConfig);
            LOG.info("Log config {} is sent for topology {}", logConfig, topologyName);
        }
    });
}
Also used : HashMap(java.util.HashMap) NimbusClient(org.apache.storm.utils.NimbusClient) LogLevel(org.apache.storm.generated.LogLevel) Nimbus(org.apache.storm.generated.Nimbus) Map(java.util.Map) HashMap(java.util.HashMap) LogConfig(org.apache.storm.generated.LogConfig)

Example 3 with LogConfig

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

the class LogConfigManagerTest method testProcessLogConfigChangeThrowsNullPointerExceptionWhenTargetLogLevelIsNotSet.

@Test
public void testProcessLogConfigChangeThrowsNullPointerExceptionWhenTargetLogLevelIsNotSet() {
    LogConfigManager logConfigManager = new LogConfigManager();
    LogConfig logConfig = new LogConfig();
    LogLevel logLevel = new LogLevel();
    logLevel.set_action(LogLevelAction.UPDATE);
    logLevel.set_reset_log_level("INFO");
    logConfig.put_to_named_logger_level("RESET_LOG", logLevel);
    assertThrows(NullPointerException.class, () -> logConfigManager.processLogConfigChange(logConfig));
}
Also used : LogLevel(org.apache.storm.generated.LogLevel) LogConfig(org.apache.storm.generated.LogConfig) Test(org.junit.Test)

Example 4 with LogConfig

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

the class LogConfigManagerTest method testProcessRootLogLevelToDebugSetsLoggerAndTimeout.

@Test
public void testProcessRootLogLevelToDebugSetsLoggerAndTimeout() {
    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));
        mockConfig.put_to_named_logger_level("my_debug_logger", ll("DEBUG", inThirtySeconds));
        mockConfig.put_to_named_logger_level("my_info_logger", ll("INFO", inThirtySeconds));
        mockConfig.put_to_named_logger_level("my_error_logger", ll("ERROR", inThirtySeconds));
        LOG.info("Tests {}", mockConfigAtom.get());
        LogConfigManager underTest = spy(new LogConfigManagerUnderTest(mockConfigAtom));
        underTest.processLogConfigChange(mockConfig);
        verify(underTest).setLoggerLevel(anyObject(), eq(""), eq("DEBUG"));
        verify(underTest).setLoggerLevel(anyObject(), eq("my_debug_logger"), eq("DEBUG"));
        verify(underTest).setLoggerLevel(anyObject(), eq("my_info_logger"), eq("INFO"));
        verify(underTest).setLoggerLevel(anyObject(), eq("my_error_logger"), eq("ERROR"));
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeMap(java.util.TreeMap) LogConfig(org.apache.storm.generated.LogConfig) Test(org.junit.Test)

Example 5 with LogConfig

use of org.apache.storm.generated.LogConfig 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

LogConfig (org.apache.storm.generated.LogConfig)9 LogLevel (org.apache.storm.generated.LogLevel)6 Test (org.junit.Test)4 TreeMap (java.util.TreeMap)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 BindException (java.net.BindException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IStormClusterState (org.apache.storm.cluster.IStormClusterState)2 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)2 AuthorizationException (org.apache.storm.generated.AuthorizationException)2 IllegalStateException (org.apache.storm.generated.IllegalStateException)2 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)2 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)2 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)2 NotAliveException (org.apache.storm.generated.NotAliveException)2 TException (org.apache.storm.thrift.TException)2 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)2