/** * Gives the {@link NamespaceId} for the given logging context. * * @param loggingContext the {@link LoggingContext} whose namespace id needs to be found. * @return {@link NamespaceId} for the given logging context */ public static NamespaceId getNamespaceId(LoggingContext loggingContext) { Preconditions.checkArgument(loggingContext.getSystemTagsMap().containsKey(NamespaceLoggingContext.TAG_NAMESPACE_ID), String.format("Failed to identify the namespace in the logging context '%s' since " + "it does not contains a '%s'. LoggingContexts should have a " + "namespace.", loggingContext.getSystemTagsMap(), NamespaceLoggingContext.TAG_NAMESPACE_ID)); return new NamespaceId(loggingContext.getSystemTagsMap() .get(NamespaceLoggingContext.TAG_NAMESPACE_ID).getValue()); }
/** * Gives the {@link NamespaceId} for the given logging context. * * @param loggingContext the {@link LoggingContext} whose namespace id needs to be found. * @return {@link NamespaceId} for the given logging context */ public static NamespaceId getNamespaceId(LoggingContext loggingContext) { Preconditions.checkArgument(loggingContext.getSystemTagsMap().containsKey(NamespaceLoggingContext.TAG_NAMESPACE_ID), String.format("Failed to identify the namespace in the logging context '%s' since " + "it does not contains a '%s'. LoggingContexts should have a " + "namespace.", loggingContext.getSystemTagsMap(), NamespaceLoggingContext.TAG_NAMESPACE_ID)); return new NamespaceId(loggingContext.getSystemTagsMap() .get(NamespaceLoggingContext.TAG_NAMESPACE_ID).getValue()); }
public static LoggingContext.SystemTag getEntityId(LoggingContext loggingContext) { final String tagName; if (loggingContext instanceof WorkflowLoggingContext) { tagName = WorkflowLoggingContext.TAG_WORKFLOW_ID; } else if (loggingContext instanceof MapReduceLoggingContext) { tagName = MapReduceLoggingContext.TAG_MAP_REDUCE_JOB_ID; } else if (loggingContext instanceof SparkLoggingContext) { tagName = SparkLoggingContext.TAG_SPARK_JOB_ID; } else if (loggingContext instanceof UserServiceLoggingContext) { tagName = UserServiceLoggingContext.TAG_USER_SERVICE_ID; } else if (loggingContext instanceof WorkerLoggingContext) { tagName = WorkerLoggingContext.TAG_WORKER_ID; } else { throw new IllegalArgumentException(String.format("Invalid logging context: %s", loggingContext)); } final String entityId = loggingContext.getSystemTagsMap().get(tagName).getValue(); return new LoggingContext.SystemTag() { @Override public String getName() { return tagName; } @Override public String getValue() { return entityId; } }; }
public static LoggingContext.SystemTag getEntityId(LoggingContext loggingContext) { final String tagName; if (loggingContext instanceof FlowletLoggingContext) { tagName = FlowletLoggingContext.TAG_FLOW_ID; } else if (loggingContext instanceof WorkflowLoggingContext) { tagName = WorkflowLoggingContext.TAG_WORKFLOW_ID; } else if (loggingContext instanceof MapReduceLoggingContext) { tagName = MapReduceLoggingContext.TAG_MAP_REDUCE_JOB_ID; } else if (loggingContext instanceof SparkLoggingContext) { tagName = SparkLoggingContext.TAG_SPARK_JOB_ID; } else if (loggingContext instanceof UserServiceLoggingContext) { tagName = UserServiceLoggingContext.TAG_USER_SERVICE_ID; } else if (loggingContext instanceof WorkerLoggingContext) { tagName = WorkerLoggingContext.TAG_WORKER_ID; } else { throw new IllegalArgumentException(String.format("Invalid logging context: %s", loggingContext)); } final String entityId = loggingContext.getSystemTagsMap().get(tagName).getValue(); return new LoggingContext.SystemTag() { @Override public String getName() { return tagName; } @Override public String getValue() { return entityId; } }; }
/** * Computes a partition key based on the given {@link LoggingContext}. */ public String getPartitionKey(LoggingContext loggingContext) { String namespaceId = loggingContext.getSystemTagsMap().get(NamespaceLoggingContext.TAG_NAMESPACE_ID).getValue(); if (NamespaceId.SYSTEM.getNamespace().equals(namespaceId)) { return loggingContext.getLogPartition(); } switch (this) { case PROGRAM: return loggingContext.getLogPartition(); case APPLICATION: return namespaceId + ":" + loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_APPLICATION_ID).getValue(); default: // this should never happen throw new IllegalArgumentException( String.format("Invalid log partition type %s. Allowed partition types are program/application", getClass())); } } }
/** * Computes a partition key based on the given {@link LoggingContext}. */ public String getPartitionKey(LoggingContext loggingContext) { String namespaceId = loggingContext.getSystemTagsMap().get(NamespaceLoggingContext.TAG_NAMESPACE_ID).getValue(); if (NamespaceId.SYSTEM.getNamespace().equals(namespaceId)) { return loggingContext.getLogPartition(); } switch (this) { case PROGRAM: return loggingContext.getLogPartition(); case APPLICATION: return namespaceId + ":" + loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_APPLICATION_ID).getValue(); default: // this should never happen throw new IllegalArgumentException( String.format("Invalid log partition type %s. Allowed partition types are program/application", getClass())); } } }
/** * get log path identifier from the logging context * @param loggingContext * @return */ public static LogPathIdentifier getLogPathIdentifier(LoggingContext loggingContext) { Map<String, LoggingContext.SystemTag> tagMap = loggingContext.getSystemTagsMap(); String namespace = tagMap.containsKey(NamespaceLoggingContext.TAG_NAMESPACE_ID) ? tagMap.get(NamespaceLoggingContext.TAG_NAMESPACE_ID).getValue() : tagMap.get(ServiceLoggingContext.TAG_SYSTEM_ID).getValue(); if (loggingContext instanceof ServiceLoggingContext) { String entityId = loggingContext.getSystemTagsMap().get(ServiceLoggingContext.TAG_SERVICE_ID).getValue(); return new LogPathIdentifier(namespace, Constants.Logging.COMPONENT_NAME, entityId); } else { String appId = loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_APPLICATION_ID).getValue(); String entityId = LoggingContextHelper.getEntityId(loggingContext).getValue(); return new LogPathIdentifier(namespace, appId, entityId); } }
/** * get log path identifier from the logging context * @param loggingContext * @return */ public static LogPathIdentifier getLogPathIdentifier(LoggingContext loggingContext) { Map<String, LoggingContext.SystemTag> tagMap = loggingContext.getSystemTagsMap(); String namespace = tagMap.containsKey(NamespaceLoggingContext.TAG_NAMESPACE_ID) ? tagMap.get(NamespaceLoggingContext.TAG_NAMESPACE_ID).getValue() : tagMap.get(ServiceLoggingContext.TAG_SYSTEM_ID).getValue(); if (loggingContext instanceof ServiceLoggingContext) { String entityId = loggingContext.getSystemTagsMap().get(ServiceLoggingContext.TAG_SERVICE_ID).getValue(); return new LogPathIdentifier(namespace, Constants.Logging.COMPONENT_NAME, entityId); } else { String appId = loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_APPLICATION_ID).getValue(); String entityId = LoggingContextHelper.getEntityId(loggingContext).getValue(); return new LogPathIdentifier(namespace, appId, entityId); } }
private static Map<String, String> getMetricsTagsFromLoggingContext(LoggingContext context) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); Map<String, LoggingContext.SystemTag> loggingTags = context.getSystemTagsMap(); String namespace = getValueFromTag(loggingTags.get(NamespaceLoggingContext.TAG_NAMESPACE_ID));
private static Map<String, String> getMetricsTagsFromLoggingContext(LoggingContext context) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); Map<String, LoggingContext.SystemTag> loggingTags = context.getSystemTagsMap(); String namespace = getValueFromTag(loggingTags.get(NamespaceLoggingContext.TAG_NAMESPACE_ID));
public static Filter createFilter(LoggingContext loggingContext) { if (loggingContext instanceof ServiceLoggingContext) { LoggingContext.SystemTag systemTag = getByNamespaceOrSystemID(loggingContext.getSystemTagsMap()); if (systemTag == null) { throw new IllegalArgumentException("No namespace or system id present"); String componentId = loggingContext.getSystemTagsMap().get(ServiceLoggingContext.TAG_COMPONENT_ID).getValue(); String tagName = ServiceLoggingContext.TAG_SERVICE_ID; String entityId = loggingContext.getSystemTagsMap().get(ServiceLoggingContext.TAG_SERVICE_ID).getValue(); ImmutableList.Builder<Filter> filterBuilder = ImmutableList.builder(); String namespaceId = loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_NAMESPACE_ID).getValue(); String applId = loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_APPLICATION_ID).getValue(); Map<String, LoggingContext.SystemTag> systemTagsMap = loggingContext.getSystemTagsMap(); LoggingContext.SystemTag programTag = systemTagsMap.get(WorkflowProgramLoggingContext.TAG_WORKFLOW_MAP_REDUCE_ID); LoggingContext.SystemTag runId = loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_RUN_ID); if (runId != null && runId.getValue() != null) { filterBuilder.add(new MdcExpression(ApplicationLoggingContext.TAG_RUN_ID, runId.getValue()));
public static Filter createFilter(LoggingContext loggingContext) { if (loggingContext instanceof ServiceLoggingContext) { LoggingContext.SystemTag systemTag = getByNamespaceOrSystemID(loggingContext.getSystemTagsMap()); if (systemTag == null) { throw new IllegalArgumentException("No namespace or system id present"); String componentId = loggingContext.getSystemTagsMap().get(ServiceLoggingContext.TAG_COMPONENT_ID).getValue(); String tagName = ServiceLoggingContext.TAG_SERVICE_ID; String entityId = loggingContext.getSystemTagsMap().get(ServiceLoggingContext.TAG_SERVICE_ID).getValue(); ImmutableList.Builder<Filter> filterBuilder = ImmutableList.builder(); String namespaceId = loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_NAMESPACE_ID).getValue(); String applId = loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_APPLICATION_ID).getValue(); Map<String, LoggingContext.SystemTag> systemTagsMap = loggingContext.getSystemTagsMap(); LoggingContext.SystemTag programTag = systemTagsMap.get(WorkflowProgramLoggingContext.TAG_WORKFLOW_MAP_REDUCE_ID); LoggingContext.SystemTag runId = loggingContext.getSystemTagsMap().get(ApplicationLoggingContext.TAG_RUN_ID); if (runId != null && runId.getValue() != null) { filterBuilder.add(new MdcExpression(ApplicationLoggingContext.TAG_RUN_ID, runId.getValue()));