parent
53d25999f3
commit
5d909a969f
|
|
@ -193,8 +193,8 @@ public class EndpointAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public FlywayEndpoint flywayEndpoint(List<Flyway> flyway) {
|
public FlywayEndpoint flywayEndpoint(Map<String, Flyway> flyways) {
|
||||||
return new FlywayEndpoint(flyway);
|
return new FlywayEndpoint(flyways);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -206,8 +206,9 @@ public class EndpointAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public LiquibaseEndpoint liquibaseEndpoint(List<SpringLiquibase> liquibase) {
|
public LiquibaseEndpoint liquibaseEndpoint(
|
||||||
return new LiquibaseEndpoint(liquibase);
|
Map<String, SpringLiquibase> liquibases) {
|
||||||
|
return new LiquibaseEndpoint(liquibases);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.endpoint;
|
package org.springframework.boot.actuate.endpoint;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DatabaseMetaData;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -31,7 +27,7 @@ import org.flywaydb.core.api.MigrationInfo;
|
||||||
import org.flywaydb.core.api.MigrationState;
|
import org.flywaydb.core.api.MigrationState;
|
||||||
import org.flywaydb.core.api.MigrationType;
|
import org.flywaydb.core.api.MigrationType;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.FlywayEndpoint.FlywayMigration;
|
import org.springframework.boot.actuate.endpoint.FlywayEndpoint.FlywayReport;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
|
@ -44,48 +40,54 @@ import org.springframework.util.Assert;
|
||||||
* @since 1.3.0
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "endpoints.flyway")
|
@ConfigurationProperties(prefix = "endpoints.flyway")
|
||||||
public class FlywayEndpoint extends AbstractEndpoint<Map<String, List<FlywayMigration>>> {
|
public class FlywayEndpoint extends AbstractEndpoint<List<FlywayReport>> {
|
||||||
|
|
||||||
private final List<Flyway> flyway;
|
private final Map<String, Flyway> flyways;
|
||||||
|
|
||||||
public FlywayEndpoint(Flyway flyway) {
|
public FlywayEndpoint(Flyway flyway) {
|
||||||
this(Collections.singletonList(flyway));
|
this(Collections.singletonMap("default", flyway));
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlywayEndpoint(List<Flyway> flyway) {
|
public FlywayEndpoint(Map<String, Flyway> flyways) {
|
||||||
super("flyway");
|
super("flyway");
|
||||||
Assert.notNull(flyway, "Flyway must not be null");
|
Assert.notEmpty(flyways, "Flyways must be specified");
|
||||||
this.flyway = flyway;
|
this.flyways = flyways;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<FlywayMigration>> invoke() {
|
public List<FlywayReport> invoke() {
|
||||||
Map<String, List<FlywayMigration>> migrations = new HashMap<String, List<FlywayMigration>>();
|
List<FlywayReport> reports = new ArrayList<FlywayReport>();
|
||||||
for (Flyway flyway : this.flyway) {
|
for (Map.Entry<String, Flyway> entry : this.flyways.entrySet()) {
|
||||||
Connection connection = null;
|
List<FlywayMigration> migrations = new ArrayList<FlywayMigration>();
|
||||||
try {
|
for (MigrationInfo info : entry.getValue().info().all()) {
|
||||||
connection = flyway.getDataSource().getConnection();
|
migrations.add(new FlywayMigration(info));
|
||||||
DatabaseMetaData metaData = connection.getMetaData();
|
|
||||||
|
|
||||||
List<FlywayMigration> migration = new ArrayList<FlywayMigration>();
|
|
||||||
for (MigrationInfo info : flyway.info().all()) {
|
|
||||||
migration.add(new FlywayMigration(info));
|
|
||||||
}
|
|
||||||
migrations.put(metaData.getURL(), migration);
|
|
||||||
}
|
|
||||||
catch (SQLException e) {
|
|
||||||
//Continue
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
try {
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e) {
|
|
||||||
//Continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
reports.add(new FlywayReport(entry.getKey(), migrations));
|
||||||
}
|
}
|
||||||
return migrations;
|
return reports;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flyway report for one datasource.
|
||||||
|
*/
|
||||||
|
public static class FlywayReport {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final List<FlywayMigration> migrations;
|
||||||
|
|
||||||
|
public FlywayReport(String name, List<FlywayMigration> migrations) {
|
||||||
|
this.name = name;
|
||||||
|
this.migrations = migrations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FlywayMigration> getMigrations() {
|
||||||
|
return this.migrations;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.endpoint;
|
package org.springframework.boot.actuate.endpoint;
|
||||||
|
|
||||||
import java.sql.DatabaseMetaData;
|
import java.util.ArrayList;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -29,9 +27,9 @@ import liquibase.changelog.StandardChangeLogHistoryService;
|
||||||
import liquibase.database.Database;
|
import liquibase.database.Database;
|
||||||
import liquibase.database.DatabaseFactory;
|
import liquibase.database.DatabaseFactory;
|
||||||
import liquibase.database.jvm.JdbcConnection;
|
import liquibase.database.jvm.JdbcConnection;
|
||||||
import liquibase.exception.DatabaseException;
|
|
||||||
import liquibase.integration.spring.SpringLiquibase;
|
import liquibase.integration.spring.SpringLiquibase;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.endpoint.LiquibaseEndpoint.LiquibaseReport;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
|
@ -42,50 +40,68 @@ import org.springframework.util.Assert;
|
||||||
* @since 1.3.0
|
* @since 1.3.0
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "endpoints.liquibase")
|
@ConfigurationProperties(prefix = "endpoints.liquibase")
|
||||||
public class LiquibaseEndpoint extends AbstractEndpoint<Map<String, List<Map<String, ?>>>> {
|
public class LiquibaseEndpoint extends AbstractEndpoint<List<LiquibaseReport>> {
|
||||||
|
|
||||||
private final List<SpringLiquibase> liquibase;
|
private final Map<String, SpringLiquibase> liquibases;
|
||||||
|
|
||||||
public LiquibaseEndpoint(SpringLiquibase liquibase) {
|
public LiquibaseEndpoint(SpringLiquibase liquibase) {
|
||||||
this(Collections.singletonList(liquibase));
|
this(Collections.singletonMap("default", liquibase));
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiquibaseEndpoint(List<SpringLiquibase> liquibase) {
|
public LiquibaseEndpoint(Map<String, SpringLiquibase> liquibase) {
|
||||||
super("liquibase");
|
super("liquibase");
|
||||||
Assert.notNull(liquibase, "Liquibase must not be null");
|
Assert.notEmpty(liquibase, "Liquibase must be specified");
|
||||||
this.liquibase = liquibase;
|
this.liquibases = liquibase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<Map<String, ?>>> invoke() {
|
public List<LiquibaseReport> invoke() {
|
||||||
Map<String, List<Map<String, ?>>> services = new HashMap<String, List<Map<String, ?>>>();
|
List<LiquibaseReport> reports = new ArrayList<LiquibaseReport>();
|
||||||
|
|
||||||
DatabaseFactory factory = DatabaseFactory.getInstance();
|
DatabaseFactory factory = DatabaseFactory.getInstance();
|
||||||
|
StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
|
||||||
for (SpringLiquibase liquibase : this.liquibase) {
|
for (Map.Entry<String, SpringLiquibase> entry : this.liquibases.entrySet()) {
|
||||||
StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
|
|
||||||
try {
|
try {
|
||||||
DatabaseMetaData metaData = liquibase.getDataSource().getConnection().getMetaData();
|
DataSource dataSource = entry.getValue().getDataSource();
|
||||||
|
JdbcConnection connection = new JdbcConnection(dataSource.getConnection());
|
||||||
try {
|
try {
|
||||||
DataSource dataSource = liquibase.getDataSource();
|
Database database = factory.findCorrectDatabaseImplementation(connection);
|
||||||
JdbcConnection connection = new JdbcConnection(dataSource.getConnection());
|
reports.add(new LiquibaseReport(entry.getKey(),
|
||||||
try {
|
service.queryDatabaseChangeLogTable(database)));
|
||||||
Database database = factory.findCorrectDatabaseImplementation(connection);
|
|
||||||
services.put(metaData.getURL(), service.queryDatabaseChangeLogTable(database));
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (DatabaseException ex) {
|
finally {
|
||||||
throw new IllegalStateException("Unable to get Liquibase changelog", ex);
|
connection.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
catch (Exception ex) {
|
||||||
//Continue
|
throw new IllegalStateException("Unable to get Liquibase changelog", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return services;
|
|
||||||
|
return reports;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liquibase report for one datasource.
|
||||||
|
*/
|
||||||
|
public static class LiquibaseReport {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private final List<Map<String, ?>> changeLogs;
|
||||||
|
|
||||||
|
public LiquibaseReport(String name, List<Map<String, ?>> changeLogs) {
|
||||||
|
this.name = name;
|
||||||
|
this.changeLogs = changeLogs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Map<String, ?>> getChangeLogs() {
|
||||||
|
return this.changeLogs;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue