@@ -0,0 +1,25 @@
|
||||
package org.springframework.cloud.config.server.diagnostics;
|
||||
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
import org.springframework.cloud.config.server.environment.JGitEnvironmentRepository;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
public class GitUriFailureAnalyzer extends AbstractFailureAnalyzer<IllegalStateException> {
|
||||
|
||||
public static final String DESCRIPTION = "Invalid config server configuration.";
|
||||
public static final String ACTION = "If you are using the git profile, you need to set a Git URI in your " +
|
||||
"configuration. If you are using a native profile and have spring.cloud.config.server.bootstrap=true, " +
|
||||
"you need to use a composite configuration.";
|
||||
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, IllegalStateException cause) {
|
||||
if(JGitEnvironmentRepository.MESSAGE.equalsIgnoreCase(cause.getMessage())) {
|
||||
return new FailureAnalysis(DESCRIPTION, ACTION, cause);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,6 +80,8 @@ import static org.eclipse.jgit.transport.ReceiveCommand.Type.DELETE;
|
||||
public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
|
||||
implements EnvironmentRepository, SearchPathLocator, InitializingBean {
|
||||
|
||||
public static final String MESSAGE = "You need to configure a uri for the git repository.";
|
||||
|
||||
private static final String FILE_URI_PREFIX = "file:";
|
||||
|
||||
private static final String LOCAL_BRANCH_REF_PREFIX = "refs/remotes/origin/";
|
||||
@@ -243,7 +245,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.state(getUri() != null,
|
||||
"You need to configure a uri for the git repository");
|
||||
MESSAGE);
|
||||
initialize();
|
||||
if (this.cloneOnStart) {
|
||||
initClonedRepository();
|
||||
|
||||
@@ -11,3 +11,6 @@ org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapApplicati
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.config.server.config.ConfigServerAutoConfiguration,\
|
||||
org.springframework.cloud.config.server.config.EncryptionAutoConfiguration
|
||||
|
||||
org.springframework.boot.diagnostics.FailureAnalyzer=\
|
||||
org.springframework.cloud.config.server.diagnostics.GitUriFailureAnalyzer
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.springframework.cloud.config.server;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.cloud.config.server.diagnostics.GitUriFailureAnalyzer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
public class NativeBootstrapFailureAnalyzerTests {
|
||||
|
||||
@Rule
|
||||
public OutputCapture outputCapture = new OutputCapture();
|
||||
|
||||
@Test
|
||||
public void contextLoads(){
|
||||
try {
|
||||
new SpringApplicationBuilder(ConfigServerApplication.class)
|
||||
.web(WebApplicationType.SERVLET).properties("spring.cloud.bootstrap.name:enable-nativebootstrap").profiles("test","native").run();
|
||||
fail("Application started successfully");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
assertThat(this.outputCapture.toString())
|
||||
.contains(GitUriFailureAnalyzer.ACTION);
|
||||
assertThat(this.outputCapture.toString()).contains(GitUriFailureAnalyzer.DESCRIPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
server:
|
||||
bootstrap: true
|
||||
Reference in New Issue
Block a user