diff --git a/src/main/java/org/dataone/cn/indexer/IndexWorker.java b/src/main/java/org/dataone/cn/indexer/IndexWorker.java index 942a815f..6b645de1 100644 --- a/src/main/java/org/dataone/cn/indexer/IndexWorker.java +++ b/src/main/java/org/dataone/cn/indexer/IndexWorker.java @@ -197,6 +197,28 @@ public static void loadExternalPropertiesFile(String propertyFile) { } } + /** + * Load an additional property file to the worker when it is necessary. + * The main reason to have this method is that metacat has two property files + * - the site property file and metacat property file. We should use this + * method to load the site property file after loading the metacat property file + * @param propertyFile + */ + public static void loadAdditionalPropertyFile (String propertyFile) { + if (propertyFile != null && !propertyFile.trim().equals("")) { + try { + //Settings.getConfiguration(); + Settings.augmentConfiguration(propertyFile); + logger.info("IndexWorker.loadAdditionalPropertyFile - loaded the properties from the file " + propertyFile); + } catch (ConfigurationException e) { + logger.error("IndexWorker.loadAdditionalPropertyFile - can't load any properties from the file " + propertyFile + + " since " + e.getMessage() + "."); + } + } else { + logger.info("IndexWorker.loadAdditionalPropertyFile - can't load an additional property file since its path is null or blank."); + } + } + /** * Default constructor to initialize the RabbitMQ service * @throws IOException diff --git a/src/test/java/org/dataone/cn/indexer/IndexWorkerTest.java b/src/test/java/org/dataone/cn/indexer/IndexWorkerTest.java index 21cb543b..2677023e 100644 --- a/src/test/java/org/dataone/cn/indexer/IndexWorkerTest.java +++ b/src/test/java/org/dataone/cn/indexer/IndexWorkerTest.java @@ -141,5 +141,36 @@ public void testLoadUserSpecifiedExternalPropertiesFile() throws Exception { } } + + /** + * Test the loadAdditionalPropertiesFile method + * @throws Exception + */ + @Test + public void testLoadAdditionalPropertiesFile() throws Exception { + String propertyFilePath = "./src/main/resources/org/dataone/configuration/index-processor.properties"; + IndexWorker.loadExternalPropertiesFile(propertyFilePath); + File defaultFile = new File (propertyFilePath); + //The one from the user specified location + assertTrue(IndexWorker.propertyFilePath.equals(propertyFilePath)); + assertTrue(Settings.getConfiguration().getString("index.d1node.baseURL"). + equals("https://valley.duckdns.org/metacat/d1/mn")); + assertTrue(Settings.getConfiguration(). + getString("index.data.root.directory").equals("/var/metacat/data")); + assertTrue(Settings.getConfiguration(). + getString("index.document.root.directory").equals("/var/metacat/documents")); + assertTrue(Settings.getConfiguration().getString("cn.router.hostname2") == null); + //load another file, it will overwrite the properties which have different values + String propertyFilePath2 = "./src/test/resources/org/dataone/configuration/index-processor-2.properties"; + IndexWorker.loadAdditionalPropertyFile(propertyFilePath2); + assertTrue(IndexWorker.propertyFilePath.equals(propertyFilePath)); + assertTrue(Settings.getConfiguration().getString("index.d1node.baseURL"). + equals("https://valley.duckdns.org/metacat/d1/mn")); + assertTrue(Settings.getConfiguration(). + getString("index.data.root.directory").equals("/objects")); + assertTrue(Settings.getConfiguration(). + getString("index.document.root.directory").equals("/objects")); + assertTrue(Settings.getConfiguration().getString("cn.router.hostname2").equals("cn.dataone.org")); + } } diff --git a/src/test/resources/org/dataone/configuration/index-processor-2.properties b/src/test/resources/org/dataone/configuration/index-processor-2.properties new file mode 100644 index 00000000..45484c02 --- /dev/null +++ b/src/test/resources/org/dataone/configuration/index-processor-2.properties @@ -0,0 +1,44 @@ +#index.d1node.baseURL=https://dev.nceas.ucsb.edu/knb/d1/mn +index.d1node.baseURL=https://valley.duckdns.org/metacat/d1/mn +index.data.root.directory=/objects +index.document.root.directory=/objects + +#The section for the rabbitMQ configuration +#index.rabbitmq.hostname=host.docker.internal +index.rabbitmq.hostname=localhost +index.rabbitmq.hostport=5672 +index.rabbitmq.username=guest +index.rabbitmq.password=guest +#If you change the number of the max priority, the existing queue must be deleted. And consumers must use the same number. +index.rabbitmq.max.priority=10 + +dataone.indexing.performance.logging.enabled=false + +#The time (millisecond) that the resource map processor waits for the solr doc readiness of its components +index.resourcemap.waitingComponent.time=600 +#The number of the attempts that the resource map processor tries to wait for the solr doc readiness of its components +index.resourcemap.waitingComponent.max.attempts=15 +#The time (millisecond) that indexer will wait to grab a newer version of solr doc when a version conflict happened +index.solr.versionConflict.waiting.time=500 +#The number of the attempts that indexer tries to grab a newer version of solr doc when a version conflict happened +index.solr.versionConflict.max.attempts=5 +#You may specify the exact number of threads the indexer will use. +#If you keep it blank, Metacat will use the default one - the system processors number minus one. If calculation result is 0, 1 will be used as the default value. +#If the one you specify exceeds the default number or is less than 1, the default one will be used as well. +index.thread.number= + +D1Client.CN_URL=https://cn.dataone.org/cn + +test.solr.port=8985 +solr.query.uri=http://localhost:${test.solr.port}/solr/collection1/select/ +solr.index.uri=http://localhost:${test.solr.port}/solr/collection1/update/?commit=true +solr.base.uri=http://localhost:${test.solr.port}/solr/collection1 +#solr.schema.path can be a url or a file path +#solr.schema.path=http://localhost:8983/solr/metacat-index/admin/file?file=schema.xml&contentType=text/xml;charset=utf-8 +solr.schema.path=./src/main/resources/solr-conf/schema.xml + +index.resourcemap.namespace=http://www.w3.org/TR/rdf-syntax-grammar;http://www.openarchives.org/ore/terms + +dataone.mn.registration.serviceType.url=https://cn-sandbox-ucsb-1.test.dataone.org/mnServiceTypes.xml + +cn.router.hostname2=cn.dataone.org \ No newline at end of file