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

The following examples show how to use org.springframework.boot.actuate.info.Info. 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
Source File: BomRangesInfoContributorTests.java    From initializr with 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 #2
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: LeaderInfoContributorTest.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: LeaderInfoContributorTest.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: BomRangesInfoContributor.java    From initializr with 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 #6
Source File: CamelInfoTest.java    From camel-spring-boot with 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 #7
Source File: TotalUsersInfoContributor.java    From tutorials with 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 #8
Source File: BomRangesInfoContributorTests.java    From initializr with 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 #9
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@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 #11
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@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 #14
Source File: DependencyRangesInfoContributor.java    From initializr with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: CamelInfoContributor.java    From camel-spring-boot with 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 #16
Source File: CustomInfoContributor.java    From ehcache3-samples with 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 #17
Source File: ClockInfoContributor.java    From kid-bank with 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 #18
Source File: LeaderInfoContributorTest.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: AppModeInfoProvider.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 4 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
   boolean appMode = rnd.nextBoolean();
   builder
      .withDetail("application-mode", appMode ? "experimental" : "stable");
}
 
Example #20
Source File: AgentConnectionTrackingServiceImpl.java    From genie with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void contribute(final Info.Builder builder) {
    final List<String> jobIds = ImmutableList.copyOf(this.jobStreamRecordsMap.keySet());
    builder.withDetail("connectedAgents", jobIds);
}
 
Example #21
Source File: BomRangesInfoContributorTests.java    From initializr with Apache License 2.0 4 votes vote down vote up
private static Info getInfo(InitializrMetadata metadata) {
	Info.Builder builder = new Info.Builder();
	new BomRangesInfoContributor(new SimpleInitializrMetadataProvider(metadata)).contribute(builder);
	return builder.build();
}
 
Example #22
Source File: LauncherInfoContributor.java    From spring-cloud-formula with Apache License 2.0 4 votes vote down vote up
@Override
public void contribute(Info.Builder builder) {
    builder.withDetail("launcher", this.generateContent());
}
 
Example #23
Source File: BomRangesInfoContributorTests.java    From initializr with Apache License 2.0 4 votes vote down vote up
@Test
void noBom() {
	InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().build();
	Info info = getInfo(metadata);
	assertThat(info.getDetails()).doesNotContainKeys("bom-ranges");
}
 
Example #24
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 4 votes vote down vote up
private static Info getInfo(InitializrMetadata metadata) {
	Info.Builder builder = new Info.Builder();
	new DependencyRangesInfoContributor(new SimpleInitializrMetadataProvider(metadata)).contribute(builder);
	return builder.build();
}
 
Example #25
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example #26
Source File: DependencyRangesInfoContributorTests.java    From initializr with Apache License 2.0 4 votes vote down vote up
@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 #27
Source File: ActiveProfilesInfoContributor.java    From jhipster with 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 #28
Source File: StatisticsContributor.java    From steady with 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 #29
Source File: CustomInformationInfo.java    From heimdall with 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 #30
Source File: InstanceInfoContributor.java    From github-analytics with 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")));
}