InfoContributor getInfoContributor() { InfoContributor infoContributor = reference.get(); if (infoContributor == null) { throw new ExpiredReferenceException(this); } return infoContributor; }
private Task<?> doIfInfoContributor(final AbstractActor<?> actor, final Consumer<ActorInfoContributorReference> synchronizedAction) { if (actor instanceof InfoContributor) { ActorInfoContributorReference actorInfoContributorReference = new ActorInfoContributorReference(actorTypeResolver, actor); synchronized (actorInfoContributorReferences) { synchronizedAction.accept(actorInfoContributorReference); } } return Task.done(); }
@Bean @ConditionalOnEnabledInfoContributor("build") @ConditionalOnSingleCandidate(BuildProperties.class) @Order(DEFAULT_ORDER) public InfoContributor buildInfoContributor(BuildProperties buildProperties) { return new BuildInfoContributor(buildProperties); }
public EndpointAutoConfiguration( ObjectProvider<HealthAggregator> healthAggregatorProvider, ObjectProvider<Map<String, HealthIndicator>> healthIndicatorsProvider, ObjectProvider<List<InfoContributor>> infoContributorsProvider, ObjectProvider<Collection<PublicMetrics>> publicMetricsProvider, ObjectProvider<TraceRepository> traceRepositoryProvider) { this.healthAggregator = healthAggregatorProvider.getIfAvailable(); this.healthIndicators = healthIndicatorsProvider.getIfAvailable(); this.infoContributors = infoContributorsProvider.getIfAvailable(); this.publicMetrics = publicMetricsProvider.getIfAvailable(); this.traceRepository = traceRepositoryProvider.getIfAvailable(); }
private static List<InfoContributor> createContributors(Map<String, Object> info, InfoContributor[] infoContributors) { List<InfoContributor> result = new ArrayList<InfoContributor>( Arrays.asList(infoContributors)); result.add(0, new MapInfoContributor(info)); return result; }
@Override public Map<String, Object> invoke() { Info.Builder builder = new Info.Builder(); for (InfoContributor contributor : this.infoContributors) { contributor.contribute(builder); } builder.withDetails(getAdditionalInfo()); Info build = builder.build(); return build.getDetails(); }
@Test public void disableEnvContributor() { load("management.info.env.enabled:false"); Map<String, InfoContributor> beans = this.context .getBeansOfType(InfoContributor.class); assertThat(beans).hasSize(0); }
@Test public void defaultInfoContributorsDisabled() { load("management.info.defaults.enabled:false"); Map<String, InfoContributor> beans = this.context .getBeansOfType(InfoContributor.class); assertThat(beans).hasSize(0); }
@Test public void defaultInfoContributorsDisabledWithCustomOne() { load(CustomInfoContributorConfiguration.class, "management.info.defaults.enabled:false"); Map<String, InfoContributor> beans = this.context .getBeansOfType(InfoContributor.class); assertThat(beans).hasSize(1); assertThat(this.context.getBean("customInfoContributor")) .isSameAs(beans.values().iterator().next()); }
@SuppressWarnings("unchecked") @Test public void gitPropertiesDefaultMode() { load(GitPropertiesConfiguration.class); Map<String, InfoContributor> beans = this.context .getBeansOfType(InfoContributor.class); assertThat(beans).containsKeys("gitInfoContributor"); Map<String, Object> content = invokeContributor( this.context.getBean("gitInfoContributor", InfoContributor.class)); Object git = content.get("git"); assertThat(git).isInstanceOf(Map.class); Map<String, Object> gitInfo = (Map<String, Object>) git; assertThat(gitInfo).containsOnlyKeys("branch", "commit"); }
@SuppressWarnings("unchecked") @Test public void gitPropertiesFullMode() { load(GitPropertiesConfiguration.class, "management.info.git.mode=full"); Map<String, Object> content = invokeContributor( this.context.getBean("gitInfoContributor", InfoContributor.class)); Object git = content.get("git"); assertThat(git).isInstanceOf(Map.class); Map<String, Object> gitInfo = (Map<String, Object>) git; assertThat(gitInfo).containsOnlyKeys("branch", "commit", "foo"); assertThat(gitInfo.get("foo")).isEqualTo("bar"); }
@SuppressWarnings("unchecked") @Test public void buildProperties() { load(BuildPropertiesConfiguration.class); Map<String, InfoContributor> beans = this.context .getBeansOfType(InfoContributor.class); assertThat(beans).containsKeys("buildInfoContributor"); Map<String, Object> content = invokeContributor( this.context.getBean("buildInfoContributor", InfoContributor.class)); Object build = content.get("build"); assertThat(build).isInstanceOf(Map.class); Map<String, Object> buildInfo = (Map<String, Object>) build; assertThat(buildInfo).containsOnlyKeys("group", "artifact", "foo"); assertThat(buildInfo.get("foo")).isEqualTo("bar"); }
@Bean public InfoContributor customInfoContributor() { return new InfoContributor() { @Override public void contribute(Info.Builder builder) { } }; }
@Bean @Order(InfoContributorAutoConfiguration.DEFAULT_ORDER - 1) public InfoContributor myInfoContributor() { return new InfoContributor() { @Override public void contribute(Info.Builder builder) { builder.withDetail("name", "bar"); builder.withDetail("version", "1.0"); } }; }
@Bean public InfoContributor infoContributor() { return new InfoContributor() { @Override public void contribute(Info.Builder builder) { builder.withDetail("key1", "value1"); } }; }
private InfoContributor infoContributor() { return new InfoContributor() { @Override public void contribute(Info.Builder builder) { builder.withDetail("key1", "value1"); } }; }
@Bean public InfoContributor beanName1() { return new InfoContributor() { @Override public void contribute(Info.Builder builder) { Map<String, Object> content = new LinkedHashMap<String, Object>(); content.put("key11", "value11"); content.put("key12", "value12"); builder.withDetail("beanName1", content); } }; }
@Bean public InfoContributor beanName2() { return new InfoContributor() { @Override public void contribute(Info.Builder builder) { Map<String, Object> content = new LinkedHashMap<String, Object>(); content.put("key21", "value21"); content.put("key22", "value22"); builder.withDetail("beanName2", content); } }; }
@Bean InfoContributor infoContributor() { return builder -> { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try { for (Resource r : resolver.getResources("classpath:configuration/*.yml")) { builder.withDetail(r.getFilename(), "/" + r.getFilename().replaceAll("\\.yml","") + "/native"); } } catch (IOException e) { throw new RuntimeException(e); } }; }
ActorInfoContributorReference(final Function<AbstractActor, Class> actorTypeResolver, final AbstractActor<?> actor) { reference = new WeakReference<>((InfoContributor) actor); name = actorTypeResolver.apply(actor).getSimpleName(); identity = ((Actor) actor).getIdentity(); }
@Bean @ConditionalOnMissingBean public InfoEndpoint infoEndpoint() throws Exception { return new InfoEndpoint(this.infoContributors == null ? Collections.<InfoContributor>emptyList() : this.infoContributors); }
/** * Create a new {@link InfoEndpoint} instance. * @param infoContributors the info contributors to use */ public InfoEndpoint(List<InfoContributor> infoContributors) { super("info", false); Assert.notNull(infoContributors, "Info contributors must not be null"); this.infoContributors = infoContributors; }
private Map<String, Object> invokeContributor(InfoContributor contributor) { Info.Builder builder = new Info.Builder(); contributor.contribute(builder); return builder.build().getDetails(); }
@Bean @Order(InfoContributorAutoConfiguration.DEFAULT_ORDER + 1) public InfoContributor myAnotherContributor(ProjectInfoProperties properties) throws IOException, BindException { return new GitFullInfoContributor(properties.getGit().getLocation()); }