Skip to content

Commit f38cb7b

Browse files
committed
Improve structure of Flyway endpoint response, add missing properties
Closes gh-9973
1 parent 83c8c0b commit f38cb7b

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

Diff for: spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/FlywayEndpoint.java

+26-23
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
package org.springframework.boot.actuate.endpoint;
1818

19-
import java.util.ArrayList;
20-
import java.util.Collections;
2119
import java.util.Date;
20+
import java.util.HashMap;
2221
import java.util.List;
2322
import java.util.Map;
23+
import java.util.stream.Collectors;
24+
import java.util.stream.Stream;
2425

2526
import org.flywaydb.core.Flyway;
2627
import org.flywaydb.core.api.MigrationInfo;
@@ -40,58 +41,46 @@
4041
* @since 1.3.0
4142
*/
4243
@ConfigurationProperties(prefix = "endpoints.flyway")
43-
public class FlywayEndpoint extends AbstractEndpoint<List<FlywayReport>> {
44+
public class FlywayEndpoint extends AbstractEndpoint<Map<String, FlywayReport>> {
4445

4546
private final Map<String, Flyway> flyways;
4647

47-
public FlywayEndpoint(Flyway flyway) {
48-
this(Collections.singletonMap("default", flyway));
49-
}
50-
5148
public FlywayEndpoint(Map<String, Flyway> flyways) {
5249
super("flyway");
5350
Assert.notEmpty(flyways, "Flyways must be specified");
5451
this.flyways = flyways;
5552
}
5653

5754
@Override
58-
public List<FlywayReport> invoke() {
59-
List<FlywayReport> reports = new ArrayList<>();
55+
public Map<String, FlywayReport> invoke() {
56+
Map<String, FlywayReport> reports = new HashMap<>();
6057
for (Map.Entry<String, Flyway> entry : this.flyways.entrySet()) {
61-
List<FlywayMigration> migrations = new ArrayList<>();
62-
for (MigrationInfo info : entry.getValue().info().all()) {
63-
migrations.add(new FlywayMigration(info));
64-
}
65-
reports.add(new FlywayReport(entry.getKey(), migrations));
58+
reports.put(entry.getKey(),
59+
new FlywayReport(Stream.of(entry.getValue().info().all())
60+
.map(FlywayMigration::new).collect(Collectors.toList())));
6661
}
6762
return reports;
6863
}
6964

7065
/**
71-
* Flyway report for one datasource.
66+
* Report for one {@link Flyway} instance.
7267
*/
7368
public static class FlywayReport {
7469

75-
private final String name;
7670
private final List<FlywayMigration> migrations;
7771

78-
public FlywayReport(String name, List<FlywayMigration> migrations) {
79-
this.name = name;
72+
public FlywayReport(List<FlywayMigration> migrations) {
8073
this.migrations = migrations;
8174
}
8275

83-
public String getName() {
84-
return this.name;
85-
}
86-
8776
public List<FlywayMigration> getMigrations() {
8877
return this.migrations;
8978
}
9079

9180
}
9281

9382
/**
94-
* Migration properties.
83+
* Details of a migration performed by Flyway.
9584
*/
9685
public static class FlywayMigration {
9786

@@ -107,8 +96,12 @@ public static class FlywayMigration {
10796

10897
private final MigrationState state;
10998

99+
private final String installedBy;
100+
110101
private final Date installedOn;
111102

103+
private final Integer installedRank;
104+
112105
private final Integer executionTime;
113106

114107
public FlywayMigration(MigrationInfo info) {
@@ -118,7 +111,9 @@ public FlywayMigration(MigrationInfo info) {
118111
this.description = info.getDescription();
119112
this.script = info.getScript();
120113
this.state = info.getState();
114+
this.installedBy = info.getInstalledBy();
121115
this.installedOn = info.getInstalledOn();
116+
this.installedRank = info.getInstalledRank();
122117
this.executionTime = info.getExecutionTime();
123118
}
124119

@@ -150,10 +145,18 @@ public MigrationState getState() {
150145
return this.state;
151146
}
152147

148+
public String getInstalledBy() {
149+
return this.installedBy;
150+
}
151+
153152
public Date getInstalledOn() {
154153
return this.installedOn;
155154
}
156155

156+
public Integer getInstalledRank() {
157+
return this.installedRank;
158+
}
159+
157160
public Integer getExecutionTime() {
158161
return this.executionTime;
159162
}

Diff for: spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MvcEndpointPathConfigurationTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure;
1818

19+
import java.util.Collections;
20+
1921
import liquibase.integration.spring.SpringLiquibase;
2022
import org.flywaydb.core.Flyway;
2123
import org.junit.After;
@@ -157,7 +159,7 @@ LoggingSystem loggingSystem() {
157159

158160
@Bean
159161
public FlywayEndpoint flyway() {
160-
return new FlywayEndpoint(new Flyway());
162+
return new FlywayEndpoint(Collections.singletonMap("flyway", new Flyway()));
161163
}
162164

163165
@Bean

Diff for: spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.actuate.endpoint;
1818

19+
import java.util.Map;
20+
1921
import org.flywaydb.core.Flyway;
2022
import org.junit.Test;
2123

@@ -48,8 +50,8 @@ public void invoke() throws Exception {
4850
public static class Config {
4951

5052
@Bean
51-
public FlywayEndpoint endpoint(Flyway flyway) {
52-
return new FlywayEndpoint(flyway);
53+
public FlywayEndpoint endpoint(Map<String, Flyway> flyways) {
54+
return new FlywayEndpoint(flyways);
5355
}
5456

5557
}

0 commit comments

Comments
 (0)