public CoordinationUtilsFactory getCoordinationUtilsFactory() { // load the class String coordinationUtilsFactoryClass = getJobCoordinationUtilsFactoryClassName(); return Util.getObj(coordinationUtilsFactoryClass, CoordinationUtilsFactory.class); }
/** * @return The hostname to use in the hostname field of the encoded * LoggingEvents. */ public static String getHostname() { try { return Util.getLocalHost().getHostName(); } catch (Exception e) { return "unknown-host"; } }
static Config mergeConfig(Map<String, String> originalConfig, Map<String, String> generatedConfig) { Map<String, String> mergedConfig = new HashMap<>(generatedConfig); originalConfig.forEach((k, v) -> { if (generatedConfig.containsKey(k) && !Objects.equals(generatedConfig.get(k), v)) { LOG.info("Replacing generated config for key: {} value: {} with original config value: {}", k, generatedConfig.get(k), v); } mergedConfig.put(k, v); }); return Util.rewriteConfig(new MapConfig(mergedConfig)); }
/** * Method invoked when the given thread terminates due to the * given uncaught exception. * <p>Any exception thrown by this method will be ignored by the * Java Virtual Machine. * * @param t the thread * @param e the exception */ @Override public void uncaughtException(Thread t, Throwable e) { String msg = String.format("Uncaught exception in thread %s.", t.getName()); LOGGER.error(msg, e); System.err.println(msg); e.printStackTrace(System.err); try { Util.logThreadDump("Thread dump from uncaught exception handler."); runnable.run(); } catch (Throwable throwable) { // Ignore to avoid further exception propagation } } }
/** * Gets the environment variables from the specified {@link CommandBuilder} and escapes certain characters. * * @param cmdBuilder the command builder containing the environment variables. * @return the map containing the escaped environment variables. */ private Map<String, String> getEscapedEnvironmentVariablesMap(CommandBuilder cmdBuilder) { Map<String, String> env = new HashMap<String, String>(); for (Map.Entry<String, String> entry : cmdBuilder.buildEnvironment().entrySet()) { String escapedValue = Util.envVarEscape(entry.getValue()); env.put(entry.getKey(), escapedValue); } return env; }
/** * Method invoked when the given thread terminates due to the * given uncaught exception. * <p>Any exception thrown by this method will be ignored by the * Java Virtual Machine. * * @param t the thread * @param e the exception */ @Override public void uncaughtException(Thread t, Throwable e) { String msg = String.format("Uncaught exception in thread %s.", t.getName()); LOGGER.error(msg, e); System.err.println(msg); e.printStackTrace(System.err); try { Util.logThreadDump("Thread dump from uncaught exception handler."); runnable.run(); } catch (Throwable throwable) { // Ignore to avoid further exception propagation } } }
/** * Gets the environment variables from the specified {@link CommandBuilder} and escapes certain characters. * * @param cmdBuilder the command builder containing the environment variables. * @return the map containing the escaped environment variables. */ private Map<String, String> getEscapedEnvironmentVariablesMap(CommandBuilder cmdBuilder) { Map<String, String> env = new HashMap<String, String>(); for (Map.Entry<String, String> entry : cmdBuilder.buildEnvironment().entrySet()) { String escapedValue = Util.envVarEscape(entry.getValue()); env.put(entry.getKey(), escapedValue); } return env; }
public CoordinationUtilsFactory getCoordinationUtilsFactory() { // load the class String coordinationUtilsFactoryClass = getJobCoordinationUtilsFactoryClassName(); return Util.getObj(coordinationUtilsFactoryClass, CoordinationUtilsFactory.class); }
/** * @return The hostname to use in the hostname field of the encoded * LoggingEvents. */ public static String getHostname() { try { return Util.getLocalHost().getHostName(); } catch (Exception e) { return "unknown-host"; } }
/** * Method invoked when the given thread terminates due to the * given uncaught exception. * <p>Any exception thrown by this method will be ignored by the * Java Virtual Machine. * * @param t the thread * @param e the exception */ @Override public void uncaughtException(Thread t, Throwable e) { String msg = String.format("Uncaught exception in thread %s.", t.getName()); LOGGER.error(msg, e); System.err.println(msg); e.printStackTrace(System.err); try { Util.logThreadDump("Thread dump from uncaught exception handler."); runnable.run(); } catch (Throwable throwable) { // Ignore to avoid further exception propagation } } }
static Config mergeConfig(Map<String, String> originalConfig, Map<String, String> generatedConfig) { Map<String, String> mergedConfig = new HashMap<>(generatedConfig); originalConfig.forEach((k, v) -> { if (generatedConfig.containsKey(k) && !Objects.equals(generatedConfig.get(k), v)) { LOG.info("Replacing generated config for key: {} value: {} with original config value: {}", k, generatedConfig.get(k), v); } mergedConfig.put(k, v); }); return Util.rewriteConfig(new MapConfig(mergedConfig)); }
env.put(ShellCommandConfig.ENV_EXECUTION_ENV_CONTAINER_ID(), Util.envVarEscape(container.getId().toString())); printContainerEnvironmentVariables(samzaContainerId, env);
public CoordinationUtilsFactory getCoordinationUtilsFactory() { // load the class String coordinationUtilsFactoryClass = getJobCoordinationUtilsFactoryClassName(); return Util.getObj(coordinationUtilsFactoryClass, CoordinationUtilsFactory.class); }
@Override public LocationIdProvider getLocationIdProvider(Config config) { return () -> new LocationId(Util.getLocalHost().getHostName()); } }
/** * Method invoked when the given thread terminates due to the * given uncaught exception. * <p>Any exception thrown by this method will be ignored by the * Java Virtual Machine. * * @param t the thread * @param e the exception */ @Override public void uncaughtException(Thread t, Throwable e) { String msg = String.format("Uncaught exception in thread %s.", t.getName()); LOGGER.error(msg, e); System.err.println(msg); e.printStackTrace(System.err); try { Util.logThreadDump("Thread dump from uncaught exception handler."); runnable.run(); } catch (Throwable throwable) { // Ignore to avoid further exception propagation } } }
static Config mergeConfig(Map<String, String> originalConfig, Map<String, String> generatedConfig) { Map<String, String> mergedConfig = new HashMap<>(generatedConfig); originalConfig.forEach((k, v) -> { if (generatedConfig.containsKey(k) && !Objects.equals(generatedConfig.get(k), v)) { LOG.info("Replacing generated config for key: {} value: {} with original config value: {}", k, generatedConfig.get(k), v); } mergedConfig.put(k, v); }); return Util.rewriteConfig(new MapConfig(mergedConfig)); }
env.put(ShellCommandConfig.ENV_EXECUTION_ENV_CONTAINER_ID(), Util.envVarEscape(container.getId().toString())); printContainerEnvironmentVariables(samzaContainerId, env);
public CoordinationUtilsFactory getCoordinationUtilsFactory() { // load the class String coordinationUtilsFactoryClass = getJobCoordinationUtilsFactoryClassName(); return Util.getObj(coordinationUtilsFactoryClass, CoordinationUtilsFactory.class); }
@Override public LocationIdProvider getLocationIdProvider(Config config) { return () -> new LocationId(Util.getLocalHost().getHostName()); } }
public void start() { if (started) { LOG.warn("Skipping attempt to start an already started ContainerHeartbeatMonitor."); return; } LOG.info("Starting ContainerHeartbeatMonitor"); scheduler.scheduleAtFixedRate(() -> { ContainerHeartbeatResponse response = containerHeartbeatClient.requestHeartbeat(); if (!response.isAlive()) { scheduler.schedule(() -> { // On timeout of container shutting down, force exit. LOG.error("Graceful shutdown timeout expired. Force exiting."); Util.logThreadDump("Thread dump at heartbeat monitor shutdown timeout."); System.exit(1); }, SHUTDOWN_TIMOUT_MS, TimeUnit.MILLISECONDS); onContainerExpired.run(); } }, 0, SCHEDULE_MS, TimeUnit.MILLISECONDS); started = true; }