protected AbstractLoggingContext() { systemTags = Maps.newHashMap(); // Try picking up the YARN container id from the env, parse it and set it to context String containerId = System.getenv("CONTAINER_ID"); if (containerId == null) { return; } try { ContainerId yarnContainerId; try { // For Hadoop 2.6+, use ContainerId.fromString(String) Method fromString = ContainerId.class.getMethod("fromString", String.class); yarnContainerId = (ContainerId) fromString.invoke(null, containerId); } catch (NoSuchMethodException e) { // This is for older Hadoop yarnContainerId = ConverterUtils.toContainerId(containerId); } setSystemTag(TAG_YARN_APP_ID, yarnContainerId.getApplicationAttemptId().getApplicationId().toString()); setSystemTag(TAG_YARN_CONTAINER_ID, yarnContainerId.toString()); } catch (Exception e) { // Ignore any exception LOG.debug("Failed to set YARN application and container id to logging context", e); } }
protected AbstractLoggingContext() { systemTags = Maps.newHashMap(); // Try picking up the YARN container id from the env, parse it and set it to context String containerId = System.getenv("CONTAINER_ID"); if (containerId == null) { return; } try { ContainerId yarnContainerId; try { // For Hadoop 2.6+, use ContainerId.fromString(String) Method fromString = ContainerId.class.getMethod("fromString", String.class); yarnContainerId = (ContainerId) fromString.invoke(null, containerId); } catch (NoSuchMethodException e) { // This is for older Hadoop yarnContainerId = ConverterUtils.toContainerId(containerId); } setSystemTag(TAG_YARN_APP_ID, yarnContainerId.getApplicationAttemptId().getApplicationId().toString()); setSystemTag(TAG_YARN_CONTAINER_ID, yarnContainerId.toString()); } catch (Exception e) { // Ignore any exception LOG.debug("Failed to set YARN application and container id to logging context", e); } }