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));
}
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);
}
});
}
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));
}
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"));
}
}
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());
}
}
Aggregations