fix(repository): Try to load the repository indefinitely
Closes gravitee-io/issues#2693
@@ -90,6 +90,37 @@ public class RepositoryPluginHandler implements PluginHandler, InitializingBean
// Load only repository plugin for a given scope (provided in the configuration)
if (repository.type().equalsIgnoreCase(requiredRepositoryType)) {
+ boolean loaded = false;
+ int tries = 0;
+
+ while (! loaded) {
+ if (tries > 0) {
+ // Wait for 5 seconds before giving an other try
+ Thread.sleep(5000);
+ }
+ loaded = loadRepository(scope, repository, plugin);
+ tries++;
+
+
+ if (! loaded) {
+ LOGGER.error("Unable to load repository {} for scope {}. Retry in 5 seconds...", scope, plugin.id());
+ }
+ }
+ } else {
+ LOGGER.debug("Scoped repository [{}] must be loaded by {}. Skipping registration",
+ scope, requiredRepositoryType);
+ }
+ } else {
+ LOGGER.warn("Repository scope {} already loaded by {}", scope,
+ repositories.get(scope));
+ }
+ }
+ } catch (Exception iae) {
+ LOGGER.error("Unexpected error while create repository instance", iae);
+ }
+ }
+
+ private boolean loadRepository(Scope scope, Repository repository, Plugin plugin) {
LOGGER.info("Repository [{}] loaded by {}", scope, repository.type());
// Not yet loaded, let's mount the repository in application context
@@ -104,21 +135,12 @@ public class RepositoryPluginHandler implements PluginHandler, InitializingBean
registerRepositoryDefinitions(repository, repoApplicationContext);
repositories.put(scope, repository);
+ return true;
} catch (Exception iae) {
LOGGER.error("Unexpected error while creating context for repository instance", iae);
pluginContextFactory.remove(plugin);
- }
- } else {
- LOGGER.debug("Scoped repository [{}] must be loaded by {}. Skipping registration",
- scope, requiredRepositoryType);
- }
- } else {
- LOGGER.warn("Repository scope {} already loaded by {}", scope,
- repositories.get(scope));
- }
- }
- } catch (Exception iae) {
- LOGGER.error("Unexpected error while create repository instance", iae);
+
+ return false;
}
}
