You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2023/03/01 19:20:11 UTC
[couchdb] 06/07: better bundle bootstrapping
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch import-nouveau-great-shuffle-wip
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit c2f37cf7251e2b44b5fc4b1746ce50f9bf3a7fa0
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Feb 28 18:24:07 2023 +0000
better bundle bootstrapping
---
java/nouveau/server/nouveau.yaml | 4 --
java/nouveau/server/pom.xml | 2 +
.../apache/couchdb/nouveau/NouveauApplication.java | 65 +++++++++-------------
.../nouveau/NouveauApplicationConfiguration.java | 14 +----
.../apache/couchdb/nouveau/IntegrationTest.java | 6 +-
5 files changed, 30 insertions(+), 61 deletions(-)
diff --git a/java/nouveau/server/nouveau.yaml b/java/nouveau/server/nouveau.yaml
index 73a211e9f..1dcf51e23 100644
--- a/java/nouveau/server/nouveau.yaml
+++ b/java/nouveau/server/nouveau.yaml
@@ -3,10 +3,6 @@ commitIntervalSeconds: 30
idleSeconds: 60
rootDir: target/indexes
-luceneBundlePaths:
- - file://${HOME}/.m2/repository/org/apache/couchdb/nouveau/lucene4/1.0-SNAPSHOT/lucene4-1.0-SNAPSHOT-dist.jar
- - file://${HOME}/.m2/repository/org/apache/couchdb/nouveau/lucene9/1.0-SNAPSHOT/lucene9-1.0-SNAPSHOT-dist.jar
-
server:
applicationConnectors:
- type: h2c
diff --git a/java/nouveau/server/pom.xml b/java/nouveau/server/pom.xml
index 1e6ed315d..696f8f274 100644
--- a/java/nouveau/server/pom.xml
+++ b/java/nouveau/server/pom.xml
@@ -135,6 +135,8 @@
<executable>java</executable>
<arguments>
<arguments>-server</arguments>
+ <argument>-Dnouveau.bundle.4=file://${user.home}/.m2/repository/org/apache/couchdb/nouveau/lucene4/${project.version}/lucene4-${project.version}-dist.jar</argument>
+ <argument>-Dnouveau.bundle.9=file://${user.home}/.m2/repository/org/apache/couchdb/nouveau/lucene9/${project.version}/lucene9-${project.version}-dist.jar</argument>
<argument>-classpath</argument>
<classpath/>
<argument>org.apache.couchdb.nouveau.NouveauApplication</argument>
diff --git a/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/NouveauApplication.java b/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/NouveauApplication.java
index 72f5469ca..8357fc4e6 100644
--- a/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/NouveauApplication.java
+++ b/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/NouveauApplication.java
@@ -13,9 +13,12 @@
package org.apache.couchdb.nouveau;
+import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.ScheduledExecutorService;
@@ -38,8 +41,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.ConfiguredBundle;
-import io.dropwizard.configuration.EnvironmentVariableSubstitutor;
-import io.dropwizard.configuration.SubstitutingSourceProvider;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
@@ -47,6 +48,8 @@ public class NouveauApplication extends Application<NouveauApplicationConfigurat
private static final Logger LOGGER = LoggerFactory.getLogger(NouveauApplication.class);
+ private Collection<LuceneBundle> bundles = new HashSet<LuceneBundle>();
+
public static void main(String[] args) throws Exception {
new NouveauApplication().run(args);
}
@@ -58,12 +61,23 @@ public class NouveauApplication extends Application<NouveauApplicationConfigurat
@Override
public void initialize(Bootstrap<NouveauApplicationConfiguration> bootstrap) {
- // Enable variable substitution with environment variables
- bootstrap.setConfigurationSourceProvider(
- new SubstitutingSourceProvider(bootstrap.getConfigurationSourceProvider(),
- new EnvironmentVariableSubstitutor(false)
- )
- );
+ // Find Lucene bundles
+ for (String name : System.getProperties().stringPropertyNames()) {
+ if (name.startsWith("nouveau.bundle.")) {
+ try {
+ ClassLoader classLoader = URLClassLoader.newInstance(new URL[]{new URL(System.getProperty(name))});
+ final ServiceLoader<ConfiguredBundle> bundleLoader = ServiceLoader.load(ConfiguredBundle.class, classLoader);
+ for (final ConfiguredBundle<Configuration> bundle : bundleLoader) {
+ if (bundle instanceof LuceneBundle) {
+ bootstrap.addBundle(bundle);
+ bundles.add((LuceneBundle<?>)bundle);
+ }
+ }
+ } catch (final MalformedURLException e) {
+ throw new Error(e);
+ }
+ }
+ }
}
@Override
@@ -73,29 +87,11 @@ public class NouveauApplication extends Application<NouveauApplicationConfigurat
final ObjectMapper objectMapper = environment.getObjectMapper();
- Class<?> dummy4Class = null;
- Class<?> dummy9Class = null;
-
- // The clever bit.
final Map<Integer, Lucene> lucenes = new HashMap<Integer, Lucene>();
- for (final URL luceneBundlePath : configuration.getLuceneBundlePaths()) {
- final ClassLoader classLoader = URLClassLoader.newInstance(new URL[]{luceneBundlePath});
- final ServiceLoader<ConfiguredBundle> bundleLoader = ServiceLoader.load(ConfiguredBundle.class, classLoader);
- for (final ConfiguredBundle<Configuration> bundle : bundleLoader) {
- if (bundle instanceof LuceneBundle) {
- bundle.run(configuration, environment);
- final Lucene lucene = ((LuceneBundle)bundle).getLucene();
- lucenes.put(lucene.getMajor(), lucene);
- LOGGER.info("Loaded bundle for Lucene {} from {}", lucene.getMajor(), luceneBundlePath);
-
- if (lucene.getMajor() == 4) {
- dummy4Class = classLoader.loadClass("org.apache.couchdb.nouveau.core.lucene4.Dummy4");
- }
- if (lucene.getMajor() == 9) {
- dummy9Class = classLoader.loadClass("org.apache.couchdb.nouveau.core.lucene9.Dummy9");
- }
- }
- }
+ for (final LuceneBundle bundle : bundles) {
+ final Lucene lucene = ((LuceneBundle)bundle).getLucene();
+ lucenes.put(lucene.getMajor(), lucene);
+ LOGGER.info("Loaded bundle for Lucene {}", lucene.getMajor());
}
if (lucenes.isEmpty()) {
@@ -127,15 +123,6 @@ public class NouveauApplication extends Application<NouveauApplicationConfigurat
// health checks
environment.healthChecks().register("analyzeResource", new AnalyzeHealthCheck(analyzeResource));
environment.healthChecks().register("indexManager", new IndexManagerHealthCheck(indexManager));
-
- LOGGER.info("object mapper:" + objectMapper.getRegisteredModuleIds());
-
- if (dummy4Class != null) {
- LOGGER.info("4: {}", objectMapper.readValue("{\"field\":12}", dummy4Class));
- }
- if (dummy9Class != null) {
- LOGGER.info("9: {}", objectMapper.readValue("{\"field\":12}", dummy9Class));
- }
}
}
diff --git a/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/NouveauApplicationConfiguration.java b/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/NouveauApplicationConfiguration.java
index 4395506a3..5be8c5a21 100644
--- a/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/NouveauApplicationConfiguration.java
+++ b/java/nouveau/server/src/main/java/org/apache/couchdb/nouveau/NouveauApplicationConfiguration.java
@@ -39,9 +39,6 @@ public class NouveauApplicationConfiguration extends Configuration {
@NotNull
private Path rootDir = null;
- @NotEmpty
- private URL[] luceneBundlePaths;
-
@JsonProperty
public void setMaxIndexesOpen(int maxIndexesOpen) {
this.maxIndexesOpen = maxIndexesOpen;
@@ -78,20 +75,11 @@ public class NouveauApplicationConfiguration extends Configuration {
return rootDir;
}
- @JsonProperty
- public void setLuceneBundlePaths(final URL... luceneBundlePaths) {
- this.luceneBundlePaths = luceneBundlePaths;
- }
-
- public URL[] getLuceneBundlePaths() {
- return luceneBundlePaths;
- }
-
@Override
public String toString() {
return "NouveauApplicationConfiguration [maxIndexesOpen=" + maxIndexesOpen + ", commitIntervalSeconds="
+ commitIntervalSeconds + ", idleSeconds=" + idleSeconds + ", rootDir=" + rootDir
- + ", luceneBundlePaths=" + Arrays.toString(luceneBundlePaths) + "]";
+ + "]";
}
}
diff --git a/java/nouveau/server/src/test/java/org/apache/couchdb/nouveau/IntegrationTest.java b/java/nouveau/server/src/test/java/org/apache/couchdb/nouveau/IntegrationTest.java
index fd82d240b..13f9048e3 100644
--- a/java/nouveau/server/src/test/java/org/apache/couchdb/nouveau/IntegrationTest.java
+++ b/java/nouveau/server/src/test/java/org/apache/couchdb/nouveau/IntegrationTest.java
@@ -58,11 +58,7 @@ public class IntegrationTest {
String.format("file://%s/.m2/repository/org/apache/couchdb/nouveau/lucene9/1.0-SNAPSHOT/lucene9-1.0-SNAPSHOT-dist.jar",
System.getProperty("user.home"));
- try {
- CONFIG.setLuceneBundlePaths(new URL(path));
- } catch (MalformedURLException e) {
- throw new Error(e);
- }
+ System.setProperty("nouveau.bundle.9", path);
APP = new DropwizardAppExtension<>(NouveauApplication.class, CONFIG);
}