-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Add failure analyzer for Flyway's bootstrap failure #16015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
57ab7ed
71fc8db
ea491d4
fc2380c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright 2012-2019 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. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.boot.diagnostics.analyzer; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; | ||
| import org.springframework.boot.diagnostics.FailureAnalysis; | ||
|
|
||
| /** | ||
| * A {@code FailureAnalyzer} that performs analysis of failures caused by a | ||
| * {@code IllegalStateException}. | ||
|
||
| * | ||
| * @author Anand Shastri | ||
| */ | ||
| public class FlywayMigrationScriptMissingFailureAnalyzer | ||
| extends AbstractFailureAnalyzer<IllegalStateException> { | ||
|
|
||
| private static final String MISSING_SCRIPT_MESSAGE = "Cannot find migrations location in"; | ||
|
|
||
| @Override | ||
| protected FailureAnalysis analyze(Throwable rootFailure, IllegalStateException cause) { | ||
| if (cause.getMessage().startsWith(MISSING_SCRIPT_MESSAGE)) { | ||
| String location = StringUtils.substringBetween(cause.getMessage(), "[", "]"); | ||
|
||
| return new FailureAnalysis("Cannot find migrations location in " + location, | ||
| " please add migrations or check your Flyway configuration", cause); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright 2012-2019 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. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.boot.diagnostics.analyzer; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import org.springframework.boot.diagnostics.FailureAnalysis; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * Tests for {@link FlywayMigrationScriptMissingFailureAnalyzer} | ||
| * | ||
| * @author Anand Shastri | ||
| */ | ||
| public class FlywayMigrationScriptMissingFailureAnalyzerTests { | ||
|
|
||
| private final FlywayMigrationScriptMissingFailureAnalyzer analyzer = new FlywayMigrationScriptMissingFailureAnalyzer(); | ||
|
|
||
| @Test | ||
| public void analysisForFlywayScriptMissingFailureWhenIllegalStateExceptionIsForFlyway() { | ||
|
||
| FailureAnalysis failureAnalysis = this.analyzer.analyze(new IllegalStateException( | ||
| "Cannot find " + "migrations location in: [classpath:db/migration] " | ||
| + "(please add migrations or check your Flyway configuration)")); | ||
|
|
||
| assertThat(failureAnalysis.getDescription()) | ||
| .endsWith("Cannot find migrations location in classpath:db/migration"); | ||
| assertThat(failureAnalysis.getAction()) | ||
| .endsWith(" please add migrations or check your Flyway configuration"); | ||
| } | ||
|
|
||
| @Test | ||
| public void analysisForFlywayScriptMissingFailureWhenIllegalStateExceptionIsNotForFlyway() { | ||
| FailureAnalysis failureAnalysis = this.analyzer | ||
| .analyze(new IllegalStateException("Some other exception")); | ||
|
|
||
| assertThat(failureAnalysis).isNull(); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This failure analyzer should belong with the rest of the Flyway support. For insance
HikariDriverConfigurationFailureAnalyzeris in thejdbcpackage of the auto-configuration module. Can you please move this class to the auto-configuration module as well (in theflywaypackage)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I have moved this class under flyway package of auto-configuration module.