@Test public void shouldAddBuildInfoToBuilder() throws Exception { DmBuildInfo dmBuildInfo = new DmBuildInfo("name","env","project"); Info.Builder builder = new Info.Builder(); dmBuildInfo.contribute(builder); Map<String,Object> buildInfo = new HashMap<>(); buildInfo.put("environment", "env"); buildInfo.put("project", "project"); buildInfo.put("name", "name"); buildInfo.put("version", "unknown"); buildInfo.put("date", "unknown"); buildInfo.put("commit", "unknown"); buildInfo.put("extra", Collections.EMPTY_MAP); Map<String,Object> map = new HashMap<>(); map.put("buildInfo",buildInfo); Info info = builder.build(); assertThat(info.getDetails(), CoreMatchers.equalTo(map)); }
@Test public void shouldAddBuildInfoToBuilderNullBuildInfo() throws Exception { DmBuildInfo dmBuildInfo = new DmBuildInfo("name","env","project",null); Info.Builder builder = new Info.Builder(); dmBuildInfo.contribute(builder); Map<String,Object> buildInfo = new HashMap<>(); buildInfo.put("environment", "env"); buildInfo.put("project", "project"); buildInfo.put("name", "name"); buildInfo.put("version", "unknown"); buildInfo.put("date", "unknown"); buildInfo.put("commit", "unknown"); buildInfo.put("extra", Collections.EMPTY_MAP); Map<String,Object> map = new HashMap<>(); map.put("buildInfo",buildInfo); Info info = builder.build(); assertThat(info.getDetails(), CoreMatchers.equalTo(map)); }
@Test public void shouldAddBuildInfoToBuilderIncludesBuildNumber() throws Exception { DmBuildInfo dmBuildInfo = new DmBuildInfo("name","env","project",BUILD_INFO_WITH_BUILD_NO); Info.Builder builder = new Info.Builder(); dmBuildInfo.contribute(builder); Map<String,Object> buildInfo = new HashMap<>(); buildInfo.put("environment", "env"); buildInfo.put("project", "project"); buildInfo.put("name", "name"); buildInfo.put("version", "1.0-42"); buildInfo.put("date", "today"); buildInfo.put("commit", "aaaaaaa"); buildInfo.put("extra", Collections.EMPTY_MAP); Map<String,Object> map = new HashMap<>(); map.put("buildInfo",buildInfo); Info info = builder.build(); assertThat(info.getDetails(), CoreMatchers.equalTo(map)); }
@Override public void contribute(Info.Builder builder) { Map<String, String> asgNames = new HashMap<String, String>(); asgNames.put("author-dispatcher", envValues.getAutoScaleGroupNameForAuthorDispatcher()); asgNames.put("publish", envValues.getAutoScaleGroupNameForPublish()); asgNames.put("publish-dispatcher", envValues.getAutoScaleGroupNameForPublishDispatcher()); builder.withDetail("auto-scaling-group-names", asgNames); Map<String, String> authorInfo = new HashMap<String, String>(); authorInfo.put("elastic-load-balancer-name", envValues.getElasticLoadBalancerNameForAuthor()); authorInfo.put("elastic-load-balancer-dns", envValues.getElasticLoadBalancerAuthorDns()); builder.withDetail("author", authorInfo); builder.withDetail("alarm-notification-topic-arn", envValues.getTopicArn()); }
@Override public void contribute(Info.Builder builder) { InetAddress ip = null; Map<String, String> hostMap = new HashMap<>(); try { ip = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } hostMap.put("ipAddress", ip.getHostAddress()); hostMap.put("hostname", ip.getHostName()); builder.withDetail("appHostInfo", hostMap); hostMap = new HashMap<>(); CommandResult commandResult = this.mongoTemplate.executeCommand("{ serverStatus: 1 }"); hostMap.put("hostname", commandResult.getString("host")); builder.withDetail("mongoDbHostInfo", hostMap); }
@Override public void contribute(Info.Builder builder) { Map<String, Object> details = new LinkedHashMap<>(); metadataProvider.get().getConfiguration().getEnv().getBoms().forEach((k, v) -> { if (v.getMappings() != null && !v.getMappings().isEmpty()) { Map<String, Object> bom = new LinkedHashMap<>(); v.getMappings().forEach(it -> { String requirement = "Spring Boot " + it.determineVersionRangeRequirement(); bom.put(it.getVersion(), requirement); }); details.put(k, bom); } }); if (!details.isEmpty()) { builder.withDetail("bom-ranges", details); } }
@Test public void dependencyNoMappingSimpleRange() { Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE"); dependency.setVersionRange("[1.1.0.RELEASE, 1.5.0.RELEASE)"); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addDependencyGroup("foo", dependency).build(); Info info = getInfo(metadata); assertThat(info.getDetails()).containsKeys("dependency-ranges"); @SuppressWarnings("unchecked") Map<String, Object> ranges = (Map<String, Object>) info.getDetails() .get("dependency-ranges"); assertThat(ranges).containsOnlyKeys("foo"); @SuppressWarnings("unchecked") Map<String, Object> foo = (Map<String, Object>) ranges.get("foo"); assertThat(foo).containsExactly( entry("1.2.3.RELEASE", "Spring Boot >=1.1.0.RELEASE and <1.5.0.RELEASE")); }
@Test public void dependencyWithMappingAndOpenRange() { Dependency dependency = Dependency.withId("foo", null, null, "0.3.0.RELEASE"); dependency.getMappings().add(Dependency.Mapping .create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE")); dependency.getMappings().add(Dependency.Mapping .create("1.2.0.RELEASE", null, null, "0.2.0.RELEASE")); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addDependencyGroup("test", dependency).build(); Info info = getInfo(metadata); assertDependencyId(info, "foo"); Map<String, Object> foo = getDependencyRangeInfo(info, "foo"); assertThat(foo).containsExactly( entry("0.1.0.RELEASE", "Spring Boot >=1.1.0.RELEASE and <1.2.0.RELEASE"), entry("0.2.0.RELEASE", "Spring Boot >=1.2.0.RELEASE")); }
@Test public void dependencyWithMappingAndNoOpenRange() { Dependency dependency = Dependency.withId("foo", null, null, "0.3.0.RELEASE"); dependency.getMappings().add(Dependency.Mapping .create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE")); dependency.getMappings().add(Dependency.Mapping .create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null, "0.2.0.RELEASE")); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addDependencyGroup("test", dependency).build(); Info info = getInfo(metadata); assertDependencyId(info, "foo"); Map<String, Object> foo = getDependencyRangeInfo(info, "foo"); assertThat(foo).containsExactly( entry("0.1.0.RELEASE", "Spring Boot >=1.1.0.RELEASE and <1.2.0.RELEASE"), entry("0.2.0.RELEASE", "Spring Boot >=1.2.0.RELEASE and <1.3.0.RELEASE"), entry("managed", "Spring Boot >=1.3.0.RELEASE")); }
@Test public void withMappings() { BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0"); bom.getMappings().add( BillOfMaterials.Mapping.create("[1.3.0.RELEASE,1.3.8.RELEASE]", "1.1.0")); bom.getMappings().add( BillOfMaterials.Mapping.create("1.3.8.BUILD-SNAPSHOT", "1.1.1-SNAPSHOT")); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addBom("foo", bom).build(); Info info = getInfo(metadata); assertThat(info.getDetails()).containsKeys("bom-ranges"); @SuppressWarnings("unchecked") Map<String, Object> ranges = (Map<String, Object>) info.getDetails() .get("bom-ranges"); assertThat(ranges).containsOnlyKeys("foo"); @SuppressWarnings("unchecked") Map<String, Object> foo = (Map<String, Object>) ranges.get("foo"); assertThat(foo).containsExactly( entry("1.1.0", "Spring Boot >=1.3.0.RELEASE and <=1.3.8.RELEASE"), entry("1.1.1-SNAPSHOT", "Spring Boot >=1.3.8.BUILD-SNAPSHOT")); }
@Override public void contribute(Info.Builder builder) { Map<String,Object> map = new LinkedHashMap<>(); map.put("environment",environment); map.put("project", project); map.put("name", name); map.put("version", version + (EMPTY.equals(build) ? "" : "-" + build)); map.put("commit", commit); map.put("date", date); map.put("extra",new HashMap<>()); builder.withDetail("buildInfo",map); }
@Test public void testContribute() { // Setup for "auto-scaling-group-names". String autoScaleGroupNameForAuthorDispatcher = "autoScaleGroupNameForAuthorDispatcher"; String autoScaleGroupNameForPublish = "autoScaleGroupNameForPublish"; String autoScaleGroupNameForPublishDispatcher = "autoScaleGroupNameForPublishDispatcher"; when(envValues.getAutoScaleGroupNameForAuthorDispatcher()).thenReturn(autoScaleGroupNameForAuthorDispatcher); when(envValues.getAutoScaleGroupNameForPublish()).thenReturn(autoScaleGroupNameForPublish); when(envValues.getAutoScaleGroupNameForPublishDispatcher()).thenReturn(autoScaleGroupNameForPublishDispatcher); // Setup for "author". String elasticLoadBalancerNameForAuthor = "elasticLoadBalancerNameForAuthor"; String elasticLoadBalancerAuthorDns = "elasticLoadBalancerAuthorDns"; when(envValues.getElasticLoadBalancerNameForAuthor()).thenReturn(elasticLoadBalancerNameForAuthor); when(envValues.getElasticLoadBalancerAuthorDns()).thenReturn(elasticLoadBalancerAuthorDns); // Setup for "alarm-notification-topic-arn" String topicArn = "topicArn"; when(envValues.getTopicArn()).thenReturn(topicArn); Info.Builder builder = new Info.Builder(); infoActuator.contribute(builder); // Validate "auto-scaling-group-names". Map<String, Object> info = builder.build().getDetails(); Map<String, String> asgNames = (Map<String, String>) info.get("auto-scaling-group-names"); assertThat(asgNames.get("author-dispatcher"), equalTo(autoScaleGroupNameForAuthorDispatcher)); assertThat(asgNames.get("publish"), equalTo(autoScaleGroupNameForPublish)); assertThat(asgNames.get("publish-dispatcher"), equalTo(autoScaleGroupNameForPublishDispatcher)); // Validate "author" Map<String, String> authorInfo = (Map<String, String>) info.get("author"); assertThat(authorInfo.get("elastic-load-balancer-name"), equalTo(elasticLoadBalancerNameForAuthor)); assertThat(authorInfo.get("elastic-load-balancer-dns"), equalTo(elasticLoadBalancerAuthorDns)); // Validate "alarm-notification-topic-arn" assertThat(info.get("alarm-notification-topic-arn"), equalTo(topicArn)); }
private void contributeUsedSkillCount(List<User> users, Info.Builder builder) { int usedSkillCount = (int) users.stream() .flatMap(p -> p.getSkillsExcludeHidden().stream()) .map(UserSkill::getName) .distinct() .count(); builder.withDetail("skills_used", usedSkillCount); }
private void contributeUserSkills(List<User> users, Info.Builder builder) { IntSummaryStatistics stats = users.stream().mapToInt(u -> u.getSkillsExcludeHidden().size()).summaryStatistics(); Map<String, Double> details = new HashMap<>(); details.put("total", (double) stats.getSum()); details.put("min", (double) stats.getMin()); details.put("max", (double) stats.getMax()); details.put("average", stats.getAverage()); builder.withDetail("personal_skills", details); }
@Override public void contribute(Info.Builder builder) { List<User> users = UserRepository.findAll(); contributeUserCount(builder); contributeSkillCount(builder); contributeUsedSkillCount(users, builder); contributeHiddenSkillCount(builder); contributeUserSkills(users, builder); }
synchronized void mergeDetailsFrom(ActorInfoContributorReference actorInfoContributorReference) { Info.Builder builder = new Info.Builder(); actorInfoContributorReference.getInfoContributor().contribute(builder); Map<String, Object> whereToPutDetails = details; for (Function<ActorInfoContributorReference, String> handler: detailLevelHandlers) { String key = handler.apply(actorInfoContributorReference); whereToPutDetails.putIfAbsent(key, new HashMap<String, Object>()); //noinspection unchecked whereToPutDetails = (Map<String, Object>) whereToPutDetails.get(key); } whereToPutDetails.putAll(builder.build().getDetails()); }
@Override public void contribute(final Info.Builder builder) { populateActorInfoContainerWhileRemovingExpiredReferences(); Map<String, Object> details = actorInfoDetailsContainer.getDetailsSnapshot(); if (!details.isEmpty()) { builder.withDetail("actors", details); } }
@Override public void contribute(final Info.Builder builder) { builder.withDetail("constructorInjectedValue", constructorInjectedValue) .withDetail("fieldInjectedValue", fieldInjectedValue); super.contribute(builder); }
@Override public void contribute(Info.Builder builder) { final Map<String, OAuth2LoginDetails> oauth2Details = settingsRepository.findOne("default").getoAuth2LoginDetails(); final Map<String, AuthProviderInfo> providers = providersMap.values() .stream() .filter(p -> !p.isConfigDynamic() || (null != oauth2Details && oauth2Details.containsKey(p.getName()))) .collect(Collectors .toMap(OAuthProvider::getName, p -> new AuthProviderInfo(p.getButton(), p.buildPath(getAuthBasePath())))); builder.withDetail("auth_extensions", providers); //@formatter:on }
@Override public void contribute(Info.Builder builder) { builder .withDetail("metadata", ImmutableMap .builder() .put("project_roles", stream(ProjectRole.values()).map(Enum::name).collect(Collectors.toList())) .build()); //@formatter:on }
@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(); }
@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); } }; }
@Test public void noDependencyWithVersion() { InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .build(); Info info = getInfo(metadata); assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges"); }
@Test public void dependencyWithNoMapping() { Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE"); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addDependencyGroup("foo", dependency).build(); Info info = getInfo(metadata); assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges"); }
@Test public void dependencyWithRangeOnArtifact() { Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE"); dependency.getMappings().add(Dependency.Mapping .create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, "foo2", null)); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addDependencyGroup("foo", dependency).build(); Info info = getInfo(metadata); assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges"); }
@Test public void dependencyWithRangeAndBom() { BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0"); Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE"); dependency.getMappings().add(Dependency.Mapping .create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE")); dependency.setBom("bom"); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addBom("bom", bom) .addDependencyGroup("foo", dependency).build(); Info info = getInfo(metadata); assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges"); }
@SuppressWarnings("unchecked") private void assertDependencyId(Info info, String... dependencyIds) { assertThat(info.getDetails()).containsKeys("dependency-ranges"); Map<String, Object> ranges = (Map<String, Object>) info.getDetails() .get("dependency-ranges"); assertThat(ranges).containsOnlyKeys(dependencyIds); }
@SuppressWarnings("unchecked") private Map<String,Object> getDependencyRangeInfo(Info info, String id) { assertThat(info.getDetails()).containsKeys("dependency-ranges"); Map<String, Object> ranges = (Map<String, Object>) info.getDetails() .get("dependency-ranges"); return (Map<String, Object>) ranges.get(id); }