Improve structure of Flyway endpoint response, add missing properties

Closes gh-9973
This commit is contained in:
Andy Wilkinson
2017-08-08 10:35:26 +01:00
parent 83c8c0b848
commit f38cb7b5d8
3 changed files with 34 additions and 27 deletions

View File

@@ -16,11 +16,12 @@
package org.springframework.boot.actuate.endpoint;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationInfo;
@@ -40,14 +41,10 @@ import org.springframework.util.Assert;
* @since 1.3.0
*/
@ConfigurationProperties(prefix = "endpoints.flyway")
public class FlywayEndpoint extends AbstractEndpoint<List<FlywayReport>> {
public class FlywayEndpoint extends AbstractEndpoint<Map<String, FlywayReport>> {
private final Map<String, Flyway> flyways;
public FlywayEndpoint(Flyway flyway) {
this(Collections.singletonMap("default", flyway));
}
public FlywayEndpoint(Map<String, Flyway> flyways) {
super("flyway");
Assert.notEmpty(flyways, "Flyways must be specified");
@@ -55,35 +52,27 @@ public class FlywayEndpoint extends AbstractEndpoint<List<FlywayReport>> {
}
@Override
public List<FlywayReport> invoke() {
List<FlywayReport> reports = new ArrayList<>();
public Map<String, FlywayReport> invoke() {
Map<String, FlywayReport> reports = new HashMap<>();
for (Map.Entry<String, Flyway> entry : this.flyways.entrySet()) {
List<FlywayMigration> migrations = new ArrayList<>();
for (MigrationInfo info : entry.getValue().info().all()) {
migrations.add(new FlywayMigration(info));
}
reports.add(new FlywayReport(entry.getKey(), migrations));
reports.put(entry.getKey(),
new FlywayReport(Stream.of(entry.getValue().info().all())
.map(FlywayMigration::new).collect(Collectors.toList())));
}
return reports;
}
/**
* Flyway report for one datasource.
* Report for one {@link Flyway} instance.
*/
public static class FlywayReport {
private final String name;
private final List<FlywayMigration> migrations;
public FlywayReport(String name, List<FlywayMigration> migrations) {
this.name = name;
public FlywayReport(List<FlywayMigration> migrations) {
this.migrations = migrations;
}
public String getName() {
return this.name;
}
public List<FlywayMigration> getMigrations() {
return this.migrations;
}
@@ -91,7 +80,7 @@ public class FlywayEndpoint extends AbstractEndpoint<List<FlywayReport>> {
}
/**
* Migration properties.
* Details of a migration performed by Flyway.
*/
public static class FlywayMigration {
@@ -107,8 +96,12 @@ public class FlywayEndpoint extends AbstractEndpoint<List<FlywayReport>> {
private final MigrationState state;
private final String installedBy;
private final Date installedOn;
private final Integer installedRank;
private final Integer executionTime;
public FlywayMigration(MigrationInfo info) {
@@ -118,7 +111,9 @@ public class FlywayEndpoint extends AbstractEndpoint<List<FlywayReport>> {
this.description = info.getDescription();
this.script = info.getScript();
this.state = info.getState();
this.installedBy = info.getInstalledBy();
this.installedOn = info.getInstalledOn();
this.installedRank = info.getInstalledRank();
this.executionTime = info.getExecutionTime();
}
@@ -150,10 +145,18 @@ public class FlywayEndpoint extends AbstractEndpoint<List<FlywayReport>> {
return this.state;
}
public String getInstalledBy() {
return this.installedBy;
}
public Date getInstalledOn() {
return this.installedOn;
}
public Integer getInstalledRank() {
return this.installedRank;
}
public Integer getExecutionTime() {
return this.executionTime;
}

View File

@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.autoconfigure;
import java.util.Collections;
import liquibase.integration.spring.SpringLiquibase;
import org.flywaydb.core.Flyway;
import org.junit.After;
@@ -157,7 +159,7 @@ public class MvcEndpointPathConfigurationTests {
@Bean
public FlywayEndpoint flyway() {
return new FlywayEndpoint(new Flyway());
return new FlywayEndpoint(Collections.singletonMap("flyway", new Flyway()));
}
@Bean

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.endpoint;
import java.util.Map;
import org.flywaydb.core.Flyway;
import org.junit.Test;
@@ -48,8 +50,8 @@ public class FlywayEndpointTests extends AbstractEndpointTests<FlywayEndpoint> {
public static class Config {
@Bean
public FlywayEndpoint endpoint(Flyway flyway) {
return new FlywayEndpoint(flyway);
public FlywayEndpoint endpoint(Map<String, Flyway> flyways) {
return new FlywayEndpoint(flyways);
}
}