本文整理了Java中org.apache.gobblin.metrics.Tag
类的一些代码示例,展示了Tag
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tag
类的具体详情如下:
包路径:org.apache.gobblin.metrics.Tag
类名称:Tag
[英]A class representing a dimension or property associated with a Taggable.
[中]表示与标记关联的维度或属性的类。
代码示例来源:origin: apache/incubator-gobblin
@Override
public List<Tag<?>> getTags() {
ImmutableList.Builder<Tag<?>> builder = ImmutableList.builder();
for (Map.Entry<String, Object> entry : this.tags.entrySet()) {
builder.add(new Tag<Object>(entry.getKey(), entry.getValue()));
}
return builder.build();
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Get additional {@link Tag}s required for any type of reporting.
*/
private List<? extends Tag<?>> getMetadataTags(String applicationName, String applicationId) {
return Tag.fromMap(
new ImmutableMap.Builder<String, Object>().put(GobblinClusterMetricTagNames.APPLICATION_NAME, applicationName)
.put(GobblinClusterMetricTagNames.APPLICATION_ID, applicationId).build());
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Converts a wildcard {@link Tag} to a {@link String} {@link Tag}. This method uses the {@link Object#toString()}
* method to convert the wildcard type to a {@link String}.
*
* @param tag a {@link Tag} that should be converted to a {@link Tag} with value of type {@link String}
*
* @return a {@link Tag} with a {@link String} value
*/
public static Tag<String> tagValueToString(Tag<?> tag) {
return new Tag<>(tag.getKey(), tag.getValue().toString());
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public String toString() {
return getKey() + KEY_VALUE_SEPARATOR + getValue();
}
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Build the {@link EventSubmitter} for this class.
*/
private EventSubmitter buildEventSubmitter(List<? extends Tag<?>> tags) {
return new EventSubmitter.Builder(this.runtimeMetricContext, "gobblin.runtime")
.addMetadata(Tag.toMap(Tag.tagValuesToString(tags))).build();
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public void addTag(Tag<?> tag) {
Preconditions.checkNotNull(tag, "Cannot add a null Tag");
Preconditions.checkNotNull(tag.getValue(), "Cannot add a Tag with a null value. Tag: " + tag);
this.tags.put(tag.getKey(), tag.getValue());
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void test() throws Exception {
MetricContextFactory<SimpleScopeType> factory = new MetricContextFactory<>();
Config config = ConfigFactory.parseMap(ImmutableMap.of(
BrokerConfigurationKeyGenerator.generateKey(factory, null, null, MetricContextFactory.TAG_KEY + ".tag1"), "value1",
BrokerConfigurationKeyGenerator.generateKey(factory, null, SimpleScopeType.GLOBAL, MetricContextFactory.TAG_KEY + ".tag2"), "value2",
BrokerConfigurationKeyGenerator.generateKey(factory, null, SimpleScopeType.LOCAL, MetricContextFactory.TAG_KEY + ".tag3"), "value3"
));
SharedResourcesBroker<SimpleScopeType> rootBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config,
SimpleScopeType.GLOBAL.defaultScopeInstance());
SharedResourcesBroker<SimpleScopeType> localBroker = rootBroker.newSubscopedBuilder(SimpleScopeType.LOCAL.defaultScopeInstance()).build();
MetricContext localContext = localBroker.getSharedResource(factory, new MetricContextKey());
Map<String, String> tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(localContext.getTags()));
Assert.assertEquals(tagMap.get("tag1"), "value1");
Assert.assertEquals(tagMap.get("tag2"), "value2");
Assert.assertEquals(tagMap.get("tag3"), "value3");
MetricContext globalContext = rootBroker.getSharedResource(factory, new MetricContextKey());
Assert.assertEquals(localContext.getParent().get(), globalContext);
tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(globalContext.getTags()));
Assert.assertEquals(tagMap.get("tag1"), "value1");
Assert.assertEquals(tagMap.get("tag2"), "value2");
Assert.assertFalse(tagMap.containsKey("tag3"));
}
代码示例来源:origin: apache/incubator-gobblin
private static List<Tag<?>> tagsForContainer(State containerState, String applicationName, String taskRunnerId) {
ImmutableList.Builder<Tag<?>> tags = new ImmutableList.Builder<>();
tags.add(new Tag<>(GobblinClusterMetricTagNames.APPLICATION_NAME, applicationName));
tags.add(new Tag<>(GobblinClusterMetricTagNames.TASK_RUNNER_ID, taskRunnerId));
tags.addAll(getCustomTagsFromState(containerState));
return tags.build();
}
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testTags() {
Tag<String> jobIdTag = new Tag<String>(JOB_ID_KEY, JOB_ID);
Assert.assertEquals(jobIdTag.getKey(), JOB_ID_KEY);
Assert.assertEquals(jobIdTag.getValue(), JOB_ID);
Tag<Integer> projectVersionTag = new Tag<Integer>(PROJECT_VERSION_KEY, PROJECT_VERSION);
Assert.assertEquals(projectVersionTag.getKey(), PROJECT_VERSION_KEY);
Assert.assertEquals(projectVersionTag.getValue().intValue(), PROJECT_VERSION);
}
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Takes a {@link List} of {@link Tag}s and returns a new {@link List} with the original {@link Tag}s as well as any
* additional {@link Tag}s returned by {@link ClusterNameTags#getClusterNameTags()}.
*
* @see ClusterNameTags
*/
private static List<Tag<?>> addClusterNameTags(List<? extends Tag<?>> tags) {
return ImmutableList.<Tag<?>>builder().addAll(tags).addAll(Tag.fromMap(ClusterNameTags.getClusterNameTags()))
.build();
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Converts a {@link List} of {@link Tag}s to a {@link Map} of key, value pairs.
*
* @param tags a {@link List} of {@link Tag}s that should be converted to key, value pairs
*
* @return a {@link Map} of key, value pairs
*/
public static <T> Map<? extends String, T> toMap(List<Tag<T>> tags) {
ImmutableMap.Builder<String, T> tagsMapBuilder = ImmutableMap.builder();
for (Tag<T> tag : tags) {
tagsMapBuilder.put(tag.getKey(), tag.getValue());
}
return tagsMapBuilder.build();
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testSubTaggedMetricContext() throws Exception {
MetricContextFactory<SimpleScopeType> factory = new MetricContextFactory<>();
Config config = ConfigFactory.parseMap(ImmutableMap.of(
BrokerConfigurationKeyGenerator.generateKey(factory, null, null, MetricContextFactory.TAG_KEY + ".tag1"), "value1"
));
SharedResourcesBroker<SimpleScopeType> rootBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config,
SimpleScopeType.GLOBAL.defaultScopeInstance());
MetricContext metricContext = rootBroker.getSharedResource(factory,
new SubTaggedMetricContextKey("myMetricContext", ImmutableMap.of("tag2", "value2")));
Map<String, String> tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(metricContext.getTags()));
Assert.assertEquals(metricContext.getName(), "myMetricContext");
Assert.assertEquals(tagMap.get("tag1"), "value1");
Assert.assertEquals(tagMap.get("tag2"), "value2");
MetricContext metricContext2 = rootBroker.getSharedResource(factory,
new SubTaggedMetricContextKey("myMetricContext", ImmutableMap.of("tag2", "value2")));
Assert.assertEquals(metricContext, metricContext2);
MetricContext metricContext3 = rootBroker.getSharedResource(factory,
new SubTaggedMetricContextKey("myMetricContext", ImmutableMap.of("tag3", "value3")));
Assert.assertNotEquals(metricContext, metricContext3);
MetricContext parent = rootBroker.getSharedResource(factory, new MetricContextKey());
tagMap = (Map<String, String>) Tag.toMap(Tag.tagValuesToString(parent.getTags()));
Assert.assertEquals(metricContext.getParent().get(), parent);
Assert.assertEquals(tagMap.get("tag1"), "value1");
Assert.assertFalse(tagMap.containsKey("tag2"));
}
代码示例来源:origin: apache/incubator-gobblin
/**
* @return Tags to be applied to the {@link MetricContext} in this object. Called once in {@link #startUp()}.
* Subclasses should override this method to add additional tags.
*/
protected List<Tag<?>> getTagsForMetrics() {
List<Tag<?>> tags = Lists.newArrayList();
tags.add(new Tag<>(RuntimeMetrics.TOPIC, this.topic));
tags.add(new Tag<>(RuntimeMetrics.GROUP_ID, this.consumerConfig.groupId()));
return tags;
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testChildContext() {
this.childContext = this.context.childBuilder(CHILD_CONTEXT_NAME)
.addTag(new Tag<String>(TASK_ID_KEY, TASK_ID_PREFIX + 0))
.build();
Assert.assertEquals(this.childContext.getName(), CHILD_CONTEXT_NAME);
Assert.assertTrue(this.childContext.getParent().isPresent());
Assert.assertEquals(this.childContext.getParent().get(), this.context);
Assert.assertEquals(this.childContext.getTags().size(), 4);
Assert.assertEquals(this.childContext.getTags().get(0).getKey(), JOB_ID_KEY);
Assert.assertEquals(this.childContext.getTags().get(0).getValue(), JOB_ID_PREFIX + 0);
Assert.assertEquals(this.childContext.getTags().get(1).getKey(), MetricContext.METRIC_CONTEXT_ID_TAG_NAME);
Assert.assertEquals(this.childContext.getTags().get(2).getKey(), MetricContext.METRIC_CONTEXT_NAME_TAG_NAME);
Assert.assertEquals(this.childContext.getTags().get(3).getKey(), TASK_ID_KEY);
Assert.assertEquals(this.childContext.getTags().get(3).getValue(), TASK_ID_PREFIX + 0);
}
代码示例来源:origin: apache/incubator-gobblin
private Compactor getCompactor(CompactorFactory compactorFactory, Optional<CompactorListener> compactorListener) {
try {
return compactorFactory
.createCompactor(this.properties, Tag.fromMap(AzkabanTags.getAzkabanTags()), compactorListener);
} catch (CompactorCreationException e) {
throw new RuntimeException("Unable to create compactor", e);
}
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Add tags.
* @param tags List of {@link org.apache.gobblin.metrics.Tag}
* @return {@code this}
*/
public T withTags(List<Tag<?>> tags) {
for(Tag<?> tag : tags) {
this.tags.put(tag.getKey(), tag.getValue().toString());
}
return self();
}
代码示例来源:origin: org.apache.gobblin/gobblin-runtime
/**
* Build the {@link EventSubmitter} for this class.
*/
private EventSubmitter buildEventSubmitter(List<? extends Tag<?>> tags) {
return new EventSubmitter.Builder(this.runtimeMetricContext, "gobblin.runtime")
.addMetadata(Tag.toMap(Tag.tagValuesToString(tags))).build();
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Converts a {@link Map} of key, value pairs to a {@link List} of {@link Tag}s. Each key, value pair will be used to
* create a new {@link Tag}.
*
* @param tagsMap a {@link Map} of key, value pairs that should be converted into {@link Tag}s
*
* @return a {@link List} of {@link Tag}s
*/
public static <T> List<Tag<T>> fromMap(Map<? extends String, T> tagsMap) {
ImmutableList.Builder<Tag<T>> tagsBuilder = ImmutableList.builder();
for (Map.Entry<? extends String, T> entry : tagsMap.entrySet()) {
tagsBuilder.add(new Tag<>(entry));
}
return tagsBuilder.build();
}
代码示例来源:origin: apache/incubator-gobblin
@BeforeClass
public void setUp() {
String contextName = CONTEXT_NAME + "_" + UUID.randomUUID().toString();
this.context = MetricContext.builder(contextName)
.addTag(new Tag<String>(JOB_ID_KEY, JOB_ID_PREFIX + 0))
.build();
Assert.assertEquals(this.context.getName(), contextName);
Assert.assertTrue(this.context.getParent().isPresent());
Assert.assertEquals(this.context.getParent().get(), RootMetricContext.get());
Assert.assertEquals(this.context.getTags().size(), 3); // uuid and name tag gets added automatically
Assert.assertEquals(this.context.getTags().get(0).getKey(), JOB_ID_KEY);
Assert.assertEquals(this.context.getTags().get(0).getValue(), JOB_ID_PREFIX + 0);
// Second tag should be uuid
Assert.assertTrue(this.context.getTags().get(1).getValue().toString()
.matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"));
}
代码示例来源:origin: apache/incubator-gobblin
public AzkabanGobblinDaemon(String jobId, Properties props) throws Exception {
super(jobId, LOG);
List<Tag<?>> tags = Lists.newArrayList();
tags.addAll(Tag.fromMap(AzkabanTags.getAzkabanTags()));
RootMetricContext.get(tags);
this.daemon = new SchedulerDaemon(props);
}
内容来源于网络,如有侵权,请联系作者删除!