Added subversion fallback to working copy.
Fallback to working copy of already checkedout repo when/if subversion server becomes unavailable. Similar functionality alreay exists with git repository.
This commit is contained in:
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.cloud.config.server.environment;
|
||||
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
@@ -30,11 +28,15 @@ import org.springframework.util.StringUtils;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
import org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager;
|
||||
import org.tmatesoft.svn.core.wc.SVNClientManager;
|
||||
import org.tmatesoft.svn.core.wc.SVNStatus;
|
||||
import org.tmatesoft.svn.core.wc2.SvnCheckout;
|
||||
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
|
||||
import org.tmatesoft.svn.core.wc2.SvnTarget;
|
||||
import org.tmatesoft.svn.core.wc2.SvnUpdate;
|
||||
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
|
||||
/**
|
||||
* Subversion-backed {@link EnvironmentRepository}.
|
||||
*
|
||||
@@ -77,7 +79,7 @@ public class SvnKitEnvironmentRepository extends AbstractScmEnvironmentRepositor
|
||||
try {
|
||||
String version;
|
||||
if (new File(getWorkingDirectory(), ".svn").exists()) {
|
||||
version = update(svnOperationFactory);
|
||||
version = update(svnOperationFactory, label);
|
||||
}
|
||||
else {
|
||||
version = checkout(svnOperationFactory);
|
||||
@@ -123,19 +125,31 @@ public class SvnKitEnvironmentRepository extends AbstractScmEnvironmentRepositor
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
private String update(SvnOperationFactory svnOperationFactory) throws SVNException {
|
||||
private String update(SvnOperationFactory svnOperationFactory, String label) throws SVNException {
|
||||
logger.debug("Repo already checked out - updating instead.");
|
||||
final SvnUpdate update = svnOperationFactory.createUpdate();
|
||||
update.setSingleTarget(SvnTarget.fromFile(getWorkingDirectory()));
|
||||
long[] ids = update.run();
|
||||
StringBuilder version = new StringBuilder();
|
||||
for (long id : ids) {
|
||||
if (version.length() > 0) {
|
||||
version.append(",");
|
||||
|
||||
try {
|
||||
final SvnUpdate update = svnOperationFactory.createUpdate();
|
||||
update.setSingleTarget(SvnTarget.fromFile(getWorkingDirectory()));
|
||||
long[] ids = update.run();
|
||||
StringBuilder version = new StringBuilder();
|
||||
for (long id : ids) {
|
||||
if (version.length() > 0) {
|
||||
version.append(",");
|
||||
}
|
||||
version.append(id);
|
||||
}
|
||||
version.append(id);
|
||||
return version.toString();
|
||||
}
|
||||
return version.toString();
|
||||
catch (Exception e) {
|
||||
this.logger.warn("Could not update remote for " + label + " (current local="
|
||||
+ getWorkingDirectory().getPath() + "), remote: " + this.getUri()
|
||||
+ ")");
|
||||
}
|
||||
|
||||
final SVNStatus status = SVNClientManager.newInstance().getStatusClient()
|
||||
.doStatus(getWorkingDirectory(), false);
|
||||
return status != null ? status.getRevision().toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cloud.config.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -34,6 +33,10 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Michael Prankl
|
||||
* @author Dave Syer
|
||||
@@ -71,8 +74,16 @@ public class SubversionConfigServerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void defaultLabel() throws Exception {
|
||||
SvnKitEnvironmentRepository repository = this.context.getBean(SvnKitEnvironmentRepository.class);
|
||||
SvnKitEnvironmentRepository repository = this.context
|
||||
.getBean(SvnKitEnvironmentRepository.class);
|
||||
assertEquals("trunk", repository.getDefaultLabel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateUnavailableRepo() throws IOException {
|
||||
contextLoads();
|
||||
assertTrue(ConfigServerTestUtils.deleteLocalRepo("svn-config-repo"));
|
||||
contextLoads();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.config.server.environment;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.junit.Before;
|
||||
@@ -32,12 +30,16 @@ import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Michael Prankl
|
||||
* @author Roy Clarkson
|
||||
*/
|
||||
public class SVNKitEnvironmentRepositoryTests {
|
||||
|
||||
private static final String REPOSITORY_NAME = "svn-config-repo";
|
||||
private StandardEnvironment environment = new StandardEnvironment();
|
||||
private SvnKitEnvironmentRepository repository = new SvnKitEnvironmentRepository(
|
||||
this.environment);
|
||||
@@ -46,8 +48,8 @@ public class SVNKitEnvironmentRepositoryTests {
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
|
||||
"src/test/resources/svn-config-repo", "target/repos/svn-config-repo");
|
||||
String uri = ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/"
|
||||
+ REPOSITORY_NAME, "target/repos/" + REPOSITORY_NAME);
|
||||
this.repository.setUri(uri);
|
||||
if (this.basedir.exists()) {
|
||||
FileUtils.delete(this.basedir, FileUtils.RECURSIVE | FileUtils.RETRY);
|
||||
@@ -56,7 +58,7 @@ public class SVNKitEnvironmentRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void vanilla() {
|
||||
Environment environment = this.repository.findOne("bar", "staging", "trunk");
|
||||
Environment environment = this.findOne();
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertTrue(environment.getPropertySources().get(0).getName()
|
||||
.contains("bar.properties"));
|
||||
@@ -67,7 +69,7 @@ public class SVNKitEnvironmentRepositoryTests {
|
||||
@Test
|
||||
public void basedir() {
|
||||
this.repository.setBasedir(this.basedir);
|
||||
Environment environment = this.repository.findOne("bar", "staging", "trunk");
|
||||
Environment environment = this.findOne();
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertTrue(environment.getPropertySources().get(0).getName()
|
||||
.contains("bar.properties"));
|
||||
@@ -84,7 +86,7 @@ public class SVNKitEnvironmentRepositoryTests {
|
||||
|
||||
this.repository.setBasedir(basedirWithSpace);
|
||||
|
||||
Environment environment = this.repository.findOne("bar", "staging", "trunk");
|
||||
Environment environment = this.findOne();
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertTrue(environment.getPropertySources().get(0).getName()
|
||||
.contains("bar.properties"));
|
||||
@@ -103,8 +105,8 @@ public class SVNKitEnvironmentRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void vanilla_with_update() {
|
||||
this.repository.findOne("bar", "staging", "trunk");
|
||||
Environment environment = this.repository.findOne("bar", "staging", "trunk");
|
||||
this.findOne();
|
||||
Environment environment = this.findOne();
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertTrue(environment.getPropertySources().get(0).getName()
|
||||
.contains("bar.properties"));
|
||||
@@ -119,6 +121,17 @@ public class SVNKitEnvironmentRepositoryTests {
|
||||
assertEquals(0, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanilla_with_update_after_repo_delete() throws IOException {
|
||||
this.vanilla_with_update();
|
||||
assertTrue(ConfigServerTestUtils.deleteLocalRepo(REPOSITORY_NAME));
|
||||
this.vanilla();
|
||||
}
|
||||
|
||||
private Environment findOne() {
|
||||
return this.repository.findOne("bar", "staging", "trunk");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
@EnableConfigServer
|
||||
@@ -126,15 +139,15 @@ public class SVNKitEnvironmentRepositoryTests {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
File basedir = new File("target/config");
|
||||
String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
|
||||
"src/test/resources/svn-config-repo", "target/repos/svn-config-repo");
|
||||
String uri = ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/"
|
||||
+ REPOSITORY_NAME, "target/repos/" + REPOSITORY_NAME);
|
||||
if (basedir.exists()) {
|
||||
FileUtils.delete(basedir, FileUtils.RECURSIVE | FileUtils.RETRY);
|
||||
}
|
||||
new SpringApplicationBuilder(TestApplication.class).profiles("subversion")
|
||||
new SpringApplicationBuilder(TestApplication.class)
|
||||
.profiles("subversion")
|
||||
.properties("server.port=8888",
|
||||
"spring.cloud.config.server.svn.uri:" + uri)
|
||||
.run(args);
|
||||
"spring.cloud.config.server.svn.uri:" + uri).run(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user