Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
5d909a96
Commit
5d909a96
authored
Dec 22, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
Closes gh-6613
parent
53d25999
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
71 deletions
+90
-71
EndpointAutoConfiguration.java
...boot/actuate/autoconfigure/EndpointAutoConfiguration.java
+5
-4
FlywayEndpoint.java
...springframework/boot/actuate/endpoint/FlywayEndpoint.java
+38
-36
LiquibaseEndpoint.java
...ingframework/boot/actuate/endpoint/LiquibaseEndpoint.java
+47
-31
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java
View file @
5d909a96
...
...
@@ -193,8 +193,8 @@ public class EndpointAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public
FlywayEndpoint
flywayEndpoint
(
List
<
Flyway
>
flyway
)
{
return
new
FlywayEndpoint
(
flyway
);
public
FlywayEndpoint
flywayEndpoint
(
Map
<
String
,
Flyway
>
flyways
)
{
return
new
FlywayEndpoint
(
flyway
s
);
}
}
...
...
@@ -206,8 +206,9 @@ public class EndpointAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public
LiquibaseEndpoint
liquibaseEndpoint
(
List
<
SpringLiquibase
>
liquibase
)
{
return
new
LiquibaseEndpoint
(
liquibase
);
public
LiquibaseEndpoint
liquibaseEndpoint
(
Map
<
String
,
SpringLiquibase
>
liquibases
)
{
return
new
LiquibaseEndpoint
(
liquibases
);
}
}
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/FlywayEndpoint.java
View file @
5d909a96
...
...
@@ -16,13 +16,9 @@
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.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
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.MigrationType
;
import
org.springframework.boot.actuate.endpoint.FlywayEndpoint.Flyway
Migration
;
import
org.springframework.boot.actuate.endpoint.FlywayEndpoint.Flyway
Report
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.util.Assert
;
...
...
@@ -44,48 +40,54 @@ import org.springframework.util.Assert;
* @since 1.3.0
*/
@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
)
{
this
(
Collections
.
singleton
List
(
flyway
));
this
(
Collections
.
singleton
Map
(
"default"
,
flyway
));
}
public
FlywayEndpoint
(
List
<
Flyway
>
flyway
)
{
public
FlywayEndpoint
(
Map
<
String
,
Flyway
>
flyways
)
{
super
(
"flyway"
);
Assert
.
not
Null
(
flyway
,
"Flyway must not be null
"
);
this
.
flyway
=
flyway
;
Assert
.
not
Empty
(
flyways
,
"Flyways must be specified
"
);
this
.
flyway
s
=
flyways
;
}
@Override
public
Map
<
String
,
List
<
FlywayMigration
>>
invoke
()
{
Map
<
String
,
List
<
FlywayMigration
>>
migrations
=
new
HashMap
<
String
,
List
<
FlywayMigration
>>();
for
(
Flyway
flyway
:
this
.
flyway
)
{
Connection
connection
=
null
;
try
{
connection
=
flyway
.
getDataSource
().
getConnection
();
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
}
public
List
<
FlywayReport
>
invoke
()
{
List
<
FlywayReport
>
reports
=
new
ArrayList
<
FlywayReport
>();
for
(
Map
.
Entry
<
String
,
Flyway
>
entry
:
this
.
flyways
.
entrySet
())
{
List
<
FlywayMigration
>
migrations
=
new
ArrayList
<
FlywayMigration
>();
for
(
MigrationInfo
info
:
entry
.
getValue
().
info
().
all
())
{
migrations
.
add
(
new
FlywayMigration
(
info
));
}
reports
.
add
(
new
FlywayReport
(
entry
.
getKey
(),
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
;
}
return
migrations
;
public
List
<
FlywayMigration
>
getMigrations
()
{
return
this
.
migrations
;
}
}
/**
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpoint.java
View file @
5d909a96
...
...
@@ -16,10 +16,8 @@
package
org
.
springframework
.
boot
.
actuate
.
endpoint
;
import
java.sql.DatabaseMetaData
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -29,9 +27,9 @@ import liquibase.changelog.StandardChangeLogHistoryService;
import
liquibase.database.Database
;
import
liquibase.database.DatabaseFactory
;
import
liquibase.database.jvm.JdbcConnection
;
import
liquibase.exception.DatabaseException
;
import
liquibase.integration.spring.SpringLiquibase
;
import
org.springframework.boot.actuate.endpoint.LiquibaseEndpoint.LiquibaseReport
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.util.Assert
;
...
...
@@ -42,50 +40,68 @@ import org.springframework.util.Assert;
* @since 1.3.0
*/
@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
)
{
this
(
Collections
.
singleton
List
(
liquibase
));
this
(
Collections
.
singleton
Map
(
"default"
,
liquibase
));
}
public
LiquibaseEndpoint
(
List
<
SpringLiquibase
>
liquibase
)
{
public
LiquibaseEndpoint
(
Map
<
String
,
SpringLiquibase
>
liquibase
)
{
super
(
"liquibase"
);
Assert
.
not
Null
(
liquibase
,
"Liquibase must not be null
"
);
this
.
liquibase
=
liquibase
;
Assert
.
not
Empty
(
liquibase
,
"Liquibase must be specified
"
);
this
.
liquibase
s
=
liquibase
;
}
@Override
public
Map
<
String
,
List
<
Map
<
String
,
?>>>
invoke
()
{
Map
<
String
,
List
<
Map
<
String
,
?>>>
services
=
new
HashMap
<
String
,
List
<
Map
<
String
,
?>>>();
public
List
<
LiquibaseReport
>
invoke
()
{
List
<
LiquibaseReport
>
reports
=
new
ArrayList
<
LiquibaseReport
>();
DatabaseFactory
factory
=
DatabaseFactory
.
getInstance
();
for
(
SpringLiquibase
liquibase
:
this
.
liquibase
)
{
StandardChangeLogHistoryService
service
=
new
StandardChangeLogHistoryService
();
StandardChangeLogHistoryService
service
=
new
StandardChangeLogHistoryService
();
for
(
Map
.
Entry
<
String
,
SpringLiquibase
>
entry
:
this
.
liquibases
.
entrySet
())
{
try
{
DatabaseMetaData
metaData
=
liquibase
.
getDataSource
().
getConnection
().
getMetaData
();
DataSource
dataSource
=
entry
.
getValue
().
getDataSource
();
JdbcConnection
connection
=
new
JdbcConnection
(
dataSource
.
getConnection
());
try
{
DataSource
dataSource
=
liquibase
.
getDataSource
();
JdbcConnection
connection
=
new
JdbcConnection
(
dataSource
.
getConnection
());
try
{
Database
database
=
factory
.
findCorrectDatabaseImplementation
(
connection
);
services
.
put
(
metaData
.
getURL
(),
service
.
queryDatabaseChangeLogTable
(
database
));
}
finally
{
connection
.
close
();
}
Database
database
=
factory
.
findCorrectDatabaseImplementation
(
connection
);
reports
.
add
(
new
LiquibaseReport
(
entry
.
getKey
(),
service
.
queryDatabaseChangeLogTable
(
database
)));
}
catch
(
DatabaseException
ex
)
{
throw
new
IllegalStateException
(
"Unable to get Liquibase changelog"
,
ex
);
finally
{
connection
.
close
(
);
}
}
catch
(
SQLException
e
)
{
//Continue
catch
(
Exception
ex
)
{
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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment