Skip to content

Commit

Permalink
Add a new method which can load additional property files to accommon…
Browse files Browse the repository at this point in the history
…date the situation that metacat has more than one property files.
  • Loading branch information
taojing2002 committed Jul 11, 2023
1 parent 4b096f7 commit edbba1a
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/org/dataone/cn/indexer/IndexWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/org/dataone/cn/indexer/IndexWorkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit edbba1a

Please sign in to comment.