]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-482: Add support for tenant-specific ES index settings and mapping config.
authorRay Lee <rhlee@berkeley.edu>
Thu, 6 Sep 2018 06:41:59 +0000 (23:41 -0700)
committerRay Lee <rhlee@berkeley.edu>
Thu, 6 Sep 2018 06:41:59 +0000 (23:41 -0700)
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/config/src/main/resources/tenant.xsd

index 901113619267f0e9726e63eda8d7ddc5653b10e6..41c2bee1d8bd3462e8560f5b0575c61892476c15 100644 (file)
@@ -41,6 +41,7 @@ import org.collectionspace.services.config.service.InitHandler.Params.Field;
 import org.collectionspace.services.config.ClientType;
 import org.collectionspace.services.config.ServiceConfig;
 import org.collectionspace.services.config.service.ServiceBindingType;
+import org.collectionspace.services.config.tenant.ElasticSearchIndexConfig;
 import org.collectionspace.services.config.tenant.EventListenerConfig;
 import org.collectionspace.services.config.tenant.EventListenerConfigurations;
 import org.collectionspace.services.config.tenant.RepositoryDomainType;
@@ -1108,7 +1109,7 @@ public class ServiceMain {
                                                logger.debug(String.format("Repository name is %s", repositoryName));
                                                Document protoElasticsearchExtensionDoc = XmlTools.fileToXMLDocument(protoElasticsearchExtensionFile);
                                                
-                                               protoElasticsearchExtensionDoc = updateElasticSearchExtensionDoc(protoElasticsearchExtensionDoc, repositoryName, this.getCspaceInstanceId());
+                                               protoElasticsearchExtensionDoc = updateElasticSearchExtensionDoc(protoElasticsearchExtensionDoc, repositoryName, this.getCspaceInstanceId(), tbt.getElasticSearchIndexConfig());
                                                if (logger.isDebugEnabled()) {
                                                        String extension = protoElasticsearchExtensionDoc.asXML();
                                                        logger.trace(String.format("Updated Elasticsearch extension for '%s' repository: contents=\n", repositoryName, extension));
@@ -1325,7 +1326,7 @@ public class ServiceMain {
      * This method is filling out the elasticsearch-config.xml file with tenant specific repository information.
      */
     private Document updateElasticSearchExtensionDoc(Document elasticsearchConfigDoc, String repositoryName,
-               String cspaceInstanceId) {
+               String cspaceInstanceId, ElasticSearchIndexConfig elasticSearchIndexConfig) {
         
         // Set the <elasticSearchIndex> element's  name attribute
         String indexName = getElasticsearchIndexName(elasticsearchConfigDoc, repositoryName, cspaceInstanceId);
@@ -1336,6 +1337,19 @@ public class ServiceMain {
         elasticsearchConfigDoc = XmlTools.setAttributeValue(elasticsearchConfigDoc,
                        ConfigUtils.ELASTICSEARCH_INDEX_EXTENSION_XPATH + "/elasticSearchIndex", "repository", repositoryName);
         
+        if (elasticSearchIndexConfig != null) {
+            String settings = elasticSearchIndexConfig.getSettings();
+            String mapping = elasticSearchIndexConfig.getMapping();
+
+            if (settings != null) {
+                XmlTools.setElementValue(elasticsearchConfigDoc, ConfigUtils.ELASTICSEARCH_INDEX_EXTENSION_XPATH + "/elasticSearchIndex/settings", settings);
+            }
+
+            if (mapping != null) {
+                XmlTools.setElementValue(elasticsearchConfigDoc, ConfigUtils.ELASTICSEARCH_INDEX_EXTENSION_XPATH + "/elasticSearchIndex/mapping", mapping);
+            }
+        }
+        
         return elasticsearchConfigDoc;
     }
 
index a38278ba923b40c631c841ff9d7fd43316d508ce..592470dc6debb4145974575de08ef46268f93674 100644 (file)
@@ -51,6 +51,7 @@
             <xs:element name="properties" type="types:PropertyType" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element name="remoteClientConfigurations" type="RemoteClientConfigurations" minOccurs="0" maxOccurs="1"/>
                <xs:element name="emailConfig" type="EmailConfig" minOccurs="0" maxOccurs="1"/>
+            <xs:element name="elasticSearchIndexConfig" type="ElasticSearchIndexConfig" minOccurs="0" maxOccurs="1"/>
             <xs:element name="serviceBindings" type="service:ServiceBindingType" minOccurs="0" maxOccurs="unbounded"/>
                        <!--
                                Processing all of the tenant bindings at startup involves several sub-tasks and is expensive (slow), so we'll compute the MD5 hash of the config and persist it in the corresponding tenant record.
                        <xs:element name="passwordResetConfig" type="PasswordResetConfig" minOccurs="1" maxOccurs="1"/>                 
                </xs:sequence>
        </xs:complexType>
-       
+
+       <xs:complexType name="ElasticSearchIndexConfig">
+               <xs:annotation>
+                       <xs:documentation>Configuration of a tenant's Elasticsearch index</xs:documentation>
+               </xs:annotation>
+               <xs:sequence>
+                       <xs:element name="settings" type="xs:string" minOccurs="0" maxOccurs="1"/>
+                       <xs:element name="mapping" type="xs:string" minOccurs="0" maxOccurs="1"/>
+               </xs:sequence>
+       </xs:complexType>
+
        <xs:complexType name="SMTPConfig">
                <xs:annotation>
                        <xs:documentation>SMTP config for sending emails.</xs:documentation>