Java Code Examples for org.springframework.boot.actuate.info.Info

The following examples show how to use org.springframework.boot.actuate.info.Info. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@SuppressWarnings("unchecked")
@Test
public void infoWhenLeader() {
	given(this.mockLeadershipController.getLocalLeader())
			.willReturn(Optional.of(this.mockLeader));
	given(this.mockLeader.isCandidate(this.mockCandidate)).willReturn(true);
	given(this.mockLeader.getRole()).willReturn("testRole");
	given(this.mockLeader.getId()).willReturn("id");
	Info.Builder builder = new Info.Builder();

	leaderInfoContributor.contribute(builder);

	Map<String, Object> details = (Map<String, Object>) builder.build()
			.get("leaderElection");
	assertThat(details).containsEntry("isLeader", true);
	assertThat(details).containsEntry("leaderId", "id");
	assertThat(details).containsEntry("role", "testRole");
}
 
Example 2
@SuppressWarnings("unchecked")
@Test
public void infoWhenAnotherIsLeader() {
	given(this.mockLeadershipController.getLocalLeader())
			.willReturn(Optional.of(this.mockLeader));
	given(this.mockLeader.getRole()).willReturn("testRole");
	given(this.mockLeader.getId()).willReturn("id");
	Info.Builder builder = new Info.Builder();

	leaderInfoContributor.contribute(builder);

	Map<String, Object> details = (Map<String, Object>) builder.build()
			.get("leaderElection");
	assertThat(details).containsEntry("isLeader", false);
	assertThat(details).containsEntry("leaderId", "id");
	assertThat(details).containsEntry("role", "testRole");
}
 
Example 3
Source Project: initializr   Source File: BomRangesInfoContributor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
	Map<String, Object> details = new LinkedHashMap<>();
	this.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.determineCompatibilityRangeRequirement();
				bom.put(it.getVersion(), requirement);
			});
			details.put(k, bom);
		}
	});
	if (!details.isEmpty()) {
		builder.withDetail("bom-ranges", details);
	}
}
 
Example 4
@Test
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", null, null));
	dependency.getMappings().add(
			Dependency.Mapping.create("[1.2.0.RELEASE, 1.3.0.RELEASE)", null, null, "0.2.0.RELEASE", null, null));
	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"));
}
 
Example 5
Source Project: initializr   Source File: BomRangesInfoContributorTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
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"));
}
 
Example 6
Source Project: camel-spring-boot   Source File: CamelInfoContributor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
    if (camelContext != null) {
        builder.withDetail("camel.name", camelContext.getName());
        builder.withDetail("camel.version", camelContext.getVersion());
        if (camelContext.getUptime() != null) {
            builder.withDetail("camel.uptime", camelContext.getUptime());
            builder.withDetail("camel.uptimeMillis", camelContext.getUptimeMillis());
        }
        builder.withDetail("camel.status", camelContext.getStatus().name());
    }
}
 
Example 7
Source Project: camel-spring-boot   Source File: CamelInfoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHaveInfo() throws Exception {
    Info.Builder builder = new Info.Builder();
    indicator.contribute(builder);
    assertNotNull(builder);

    assertEquals(camelContext.getName(), builder.build().get("camel.name"));
    assertEquals(camelContext.getVersion(), builder.build().get("camel.version"));
}
 
Example 8
Source Project: kid-bank   Source File: ClockInfoContributor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
  ImmutableMap<Object, Object> infoMap = ImmutableMap.of(
      "ZoneID", clock.getZone(),
      "Date/Time", clock.instant()
  );
  builder.withDetail("Clock Info", infoMap);
}
 
Example 9
@SuppressWarnings("unchecked")
@Test
public void infoWithoutLeader() {
	Info.Builder builder = new Info.Builder();

	leaderInfoContributor.contribute(builder);

	Map<String, Object> details = (Map<String, Object>) builder.build()
			.get("leaderElection");
	assertThat(details).containsEntry("leaderId", "Unknown");
}
 
Example 10
Source Project: ehcache3-samples   Source File: CustomInfoContributor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
    String hostname;
    try {
        hostname = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        log.warn("Problem trying to resolve the hostname", e);
        hostname = "UNKNOWN";
    }
    builder.withDetail("hostname", hostname);
}
 
Example 11
@Override
public void contribute(Info.Builder builder) {
	Map<String, Object> details = new LinkedHashMap<>();
	this.metadataProvider.get().getDependencies().getAll().forEach((dependency) -> {
		if (dependency.getBom() == null) {
			contribute(details, dependency);
		}
	});
	if (!details.isEmpty()) {
		builder.withDetail("dependency-ranges", details);
	}
}
 
Example 12
@Test
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");
}
 
Example 13
@Test
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, null, null));
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", dependency)
			.build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges");
}
 
Example 14
@Test
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", null, null));
	dependency.setBom("bom");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom", bom)
			.addDependencyGroup("foo", dependency).build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges");
}
 
Example 15
@Test
void dependencyNoMappingSimpleRange() {
	Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE");
	dependency.setCompatibilityRange("[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"));
}
 
Example 16
@Test
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", null, null));
	dependency.getMappings()
			.add(Dependency.Mapping.create("1.2.0.RELEASE", null, null, "0.2.0.RELEASE", null, null));
	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"));
}
 
Example 17
Source Project: initializr   Source File: BomRangesInfoContributorTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void noMapping() {
	BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("foo", bom).build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).doesNotContainKeys("bom-ranges");
}
 
Example 18
Source Project: tutorials   Source File: TotalUsersInfoContributor.java    License: MIT License 5 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
    Map<String, Integer> userDetails = new HashMap<>();
    userDetails.put("active", userRepository.countByStatus(1));
    userDetails.put("inactive", userRepository.countByStatus(0));

    builder.withDetail("users", userDetails);
}
 
Example 19
@Override
public void contribute(Info.Builder builder) {
    builder.withDetail("launcher", this.generateContent());
}
 
Example 20
@Override
public void contribute(Info.Builder builder) {
   boolean appMode = rnd.nextBoolean();
   builder
      .withDetail("application-mode", appMode ? "experimental" : "stable");
}
 
Example 21
Source Project: steady   Source File: StatisticsContributor.java    License: Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void contribute(Info.Builder builder) {
    Map<String, Integer> vulasStats = new HashMap<String, Integer>();
    //number of vulnerable dependencies with affected true or null ('!' and '?')
   // vulasStats.put("vulnDeps_count", appVulDepRepository.countVulnDeps());
    //number of vulnerable dependencies with affected true ('!')
   //  vulasStats.put("confirmed_vulnDeps_count", appVulDepRepository.countConfirmedVulnDeps());
     
    //number of vulndeps (! ) , NOT in scope test or provided for latest g,a,v
    vulasStats.put("confirmed_vulnDeps_for_latest_versions_count", appVulDepRepository.countConfirmedVulnDepsLatestRuns()); 
     
    //number of vulndeps (! and ?) for latest g,a,v
   // vulasStats.put("vulnDeps_for_latest_versions_count", appVulDepRepository.countVulnDepsLatestRuns());
    
    //number of groups
    vulasStats.put("groups_count", appVulDepRepository.countGroups());
    //number of groups with at least one vulndeps '!' , NOT in scope test or provided 
    vulasStats.put("vulnerable_groups_count", appVulDepRepository.countConfirmedVulnerableLatestGroup());  
    //number of groups with at least one vulndeps '!' or '?'
//    vulasStats.put("vulnerable_groups_count", appVulDepRepository.countVulnerableGroups());
    
    //number of g,a
  //  vulasStats.put("group_artifacts_count", appVulDepRepository.countGroupArtifacts());
    
    //number of LATEST g,a
    vulasStats.put("latest_group_artifacts_count", appVulDepRepository.countLatestGroupArtifacts());
    //number of g,a with at least one vulndeps '!' or '?'
 //   vulasStats.put("vulnerable_group_artifacts_count", appVulDepRepository.countVulnerableGroupArtifacts());
    //number of LATEST g,a with at least one vulndeps (!) NOT in scope test or provided
    vulasStats.put("vulnerable_latest_group_artifacts_count", appVulDepRepository.countConfirmedVulnerableLatestGroupArtifacts());
    //number of LATEST g,a with at least one vulndeps (! and ?)
    //vulasStats.put("vulnerable_latest_group_artifacts_count", appVulDepRepository.countVulnerableLatestGroupArtifacts());
    
    //number of gav
    //vulasStats.put("group_artifact_versions_count", appVulDepRepository.countGAVs());
    //number of LATEST gav. only considering the latest this is equal to countLatestGroupArtifacts()
//    vulasStats.put("group_artifact_versions_count", appVulDepRepository.countLatestGAVs());
    //number of gav with at least one vulndeps '!' or '?'
 //   vulasStats.put("vulnerable_group_artifact_versions_count", appVulDepRepository.countVulnerableGAVs());
    //number of gav with at least one vulndeps '!' 
    //only considering the latest version, this returns exactly the same then countConfirmedVulnerableLatestGroupArtifacts()
//    vulasStats.put("vulnerable_latest_group_artifact_versions_count", appVulDepRepository.countConfirmedLatestVulnerableGAVs());
    //number of bugs
    vulasStats.put("bugs_count", appVulDepRepository.countBugs());

    
 
  builder.withDetail("stats", vulasStats);
 
  Map<String, ArrayList<String>> execStats = new HashMap<String, ArrayList<String>>();
  execStats.put("exe", appVulDepRepository.getGoalExecutions());
  builder.withDetail("execStats", execStats);
  
  Map<String, ArrayList<String>> gaStats = new HashMap<String, ArrayList<String>>();
  gaStats.put("group_artifact_vulndepCount", appVulDepRepository.getVulnDepsLatestGroupArtifacts());
  builder.withDetail("gaStats", gaStats);
	}
 
Example 22
Source Project: heimdall   Source File: CustomInformationInfo.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
    builder.withDetail("traces", !property.getTrace().isPrintAllTrace() && property.getMongo().getEnabled());
    builder.withDetail("analytics", property.getMongo().getEnabled());
}
 
Example 23
Source Project: github-analytics   Source File: InstanceInfoContributor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
    builder.withDetail("cf_instance",
            Collections.singletonMap("id", System.getenv("INSTANCE_GUID")));
}
 
Example 24
Source Project: flowable-engine   Source File: FlowableInfoContributor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
    builder.withDetail("flowable", version());
}
 
Example 25
@Override
public void contribute(Info.Builder builder) {
    builder.withDetail("cloud-config-label", configClientProperties.getLabel());
    builder.withDetail("cloud-config-server-configuration-sources", configServerConfig.getComposite());
}
 
Example 26
Source Project: jhipster   Source File: ActiveProfilesInfoContributor.java    License: Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void contribute(Info.Builder builder) {
    builder.withDetail(ACTIVE_PROFILES, this.profiles);
}
 
Example 27
@Override
public void contribute(Info.Builder builder) {
    builder.withDetail("version", version);
}
 
Example 28
@Test
void noDependencyWithVersion() {
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).doesNotContainKeys("dependency-ranges");
}
 
Example 29
@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);
}
 
Example 30
@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);
}