From c44dd099a432094a12131cf60dfc8a19f5aa8101 Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 13 Nov 2013 17:56:50 -0500 Subject: Implement mirror executor (issue-5) The mirror executor will fetch ref updates for repository mirrors. This feature is disabled by default and can be enabled by setting git.enableMirroring=true. The period between update checks is configurable, but it is global. An individual rpeository may not set it's own update schedule. Requirements: 1. you must manually clone the repository using native git git clone --mirror git://somewhere.com/myrepo.git 2. the "origin" remote must be the mirror source 3. the "origin" repository must be accessible without authentication OR the credentials must be embedded in the origin url (not recommended) Notes: 1. "origin" SSH urls are untested and not likely to work 2. mirrors cloned while Gitblit is running are likely to require clearing the gitblit cache (link on the repositories page of an administrator account) 3. Gitblit will automatically repair any invalid fetch refspecs with a "//" sequence. Change-Id: I4bbe3fb2df106366ae4c2313596d0fab0dfcac46 --- src/main/java/com/gitblit/GitBlit.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/gitblit/GitBlit.java') diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index f313b6e3..a0e8b0a3 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -164,7 +164,7 @@ public class GitBlit implements ServletContextListener { private final Logger logger = LoggerFactory.getLogger(GitBlit.class); - private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(5); + private final ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(10); private final List federationRegistrations = Collections .synchronizedList(new ArrayList()); @@ -207,6 +207,8 @@ public class GitBlit implements ServletContextListener { private GCExecutor gcExecutor; + private MirrorExecutor mirrorExecutor; + private TimeZone timezone; private FileBasedConfig projectConfigs; @@ -2035,6 +2037,7 @@ public class GitBlit implements ServletContextListener { model.origin = config.getString("remote", "origin", "url"); if (model.origin != null) { model.origin = model.origin.replace('\\', '/'); + model.isMirror = config.getBoolean("remote", "origin", "mirror", false); } model.preReceiveScripts = new ArrayList(Arrays.asList(config.getStringList( Constants.CONFIG_GITBLIT, null, "preReceiveScript"))); @@ -3505,6 +3508,7 @@ public class GitBlit implements ServletContextListener { mailExecutor = new MailExecutor(settings); luceneExecutor = new LuceneExecutor(settings, repositoriesFolder); gcExecutor = new GCExecutor(settings); + mirrorExecutor = new MirrorExecutor(settings); // initialize utilities String prefix = settings.getString(Keys.git.userRepositoryPrefix, "~"); @@ -3544,6 +3548,7 @@ public class GitBlit implements ServletContextListener { configureMailExecutor(); configureLuceneIndexing(); configureGarbageCollector(); + configureMirrorExecutor(); if (startFederation) { configureFederation(); } @@ -3595,6 +3600,19 @@ public class GitBlit implements ServletContextListener { } } + protected void configureMirrorExecutor() { + if (mirrorExecutor.isReady()) { + int mins = TimeUtils.convertFrequencyToMinutes(settings.getString(Keys.git.mirrorPeriod, "30 mins")); + if (mins < 5) { + mins = 5; + } + int delay = 1; + scheduledExecutor.scheduleAtFixedRate(mirrorExecutor, delay, mins, TimeUnit.MINUTES); + logger.info("Mirror executor is scheduled to fetch updates every {} minutes.", mins); + logger.info("Next scheduled mirror fetch is in {} minutes", delay); + } + } + protected void configureJGit() { // Configure JGit WindowCacheConfig cfg = new WindowCacheConfig(); @@ -3864,6 +3882,7 @@ public class GitBlit implements ServletContextListener { scheduledExecutor.shutdownNow(); luceneExecutor.close(); gcExecutor.close(); + mirrorExecutor.close(); if (fanoutService != null) { fanoutService.stop(); } -- cgit v1.2.3