This is an automated email from the ASF dual-hosted git repository.

mohandv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/metron.git


The following commit(s) were added to refs/heads/master by this push:
     new 15119cb  METRON-1940 Check if not and install Elastic search templates 
/ Solr collections when indexing server is restarted (MohanDV) closes 
apache/metron#1305
15119cb is described below

commit 15119cb16b30862e6fbba3662407ca4db4c59a3a
Author: MohanDV <[email protected]>
AuthorDate: Wed Mar 6 17:05:07 2019 +0530

    METRON-1940 Check if not and install Elastic search templates / Solr 
collections when indexing server is restarted (MohanDV) closes 
apache/metron#1305
---
 .../CURRENT/package/scripts/indexing_commands.py   | 23 ++++---
 .../CURRENT/package/scripts/indexing_master.py     | 70 ++++++++++++++--------
 2 files changed, 59 insertions(+), 34 deletions(-)

diff --git 
a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/indexing_commands.py
 
b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/indexing_commands.py
index 4802add..d557da5 100755
--- 
a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/indexing_commands.py
+++ 
b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/indexing_commands.py
@@ -209,19 +209,26 @@ class IndexingCommands:
                                   self.__params.solr_principal_name,
                                   self.__params.solr_user)
 
-        commands = IndexingCommands(params)
-        for collection_name in commands.get_solr_schemas():
-
-            # install the schema
-            cmd = format((
+        try:
+            commands = IndexingCommands(params)
+            for collection_name in commands.get_solr_schemas():
+                # install the schema
+                cmd = format((
                 "export ZOOKEEPER={solr_zookeeper_url};"
                 "export SECURITY_ENABLED={security_enabled};"
-            ))
-            cmd += "{0}/bin/create_collection.sh {1};"
+                ))
+                cmd += "{0}/bin/create_collection.sh {1};"
 
-            Execute(
+                Execute(
                 cmd.format(params.metron_home, collection_name),
                 user=self.__params.solr_user)
+            return True
+
+        except Exception as e:
+            msg = "WARNING: Solr schemas could not be installed.  " \
+                  "Is Solr running?  Will reattempt install on next start.  
error={0}"
+            Logger.warning(msg.format(e))
+            return False
 
     def solr_schema_delete(self, env):
         from params import params
diff --git 
a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/indexing_master.py
 
b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/indexing_master.py
index 9f9ab87..d058745 100755
--- 
a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/indexing_master.py
+++ 
b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/indexing_master.py
@@ -99,26 +99,20 @@ class Indexing(Script):
         commands = IndexingCommands(params)
         if params.ra_indexing_writer == 'Solr':
             # Install Solr schemas
-            try:
-                if not commands.is_solr_schema_installed():
-                    commands.solr_schema_install(env)
+            if not commands.is_solr_schema_installed():
+                if commands.solr_schema_install(env):
                     commands.set_solr_schema_installed()
 
-            except Exception as e:
-                msg = "WARNING: Solr schemas could not be installed.  " \
-                      "Is Solr running?  Will reattempt install on next start. 
 error={0}"
-                Logger.warning(msg.format(e))
-        else:
+        elif params.ra_indexing_writer == 'Elasticsearch':
             # Install elasticsearch templates
-            try:
-                if not commands.is_elasticsearch_template_installed():
-                    self.elasticsearch_template_install(env)
+            if not commands.is_elasticsearch_template_installed():
+                if self.elasticsearch_template_install(env):
                     commands.set_elasticsearch_template_installed()
 
-            except Exception as e:
-                msg = "WARNING: Elasticsearch index templates could not be 
installed.  " \
-                      "Is Elasticsearch running?  Will reattempt install on 
next start.  error={0}"
-                Logger.warning(msg.format(e))
+        else :
+            msg = "WARNING:  index schemas/templates could not be installed.  
" \
+                  "Is Indexing server configured properly ?  Will reattempt 
install on next start.  index server configured={0}"
+            Logger.warning(msg.format(params.ra_indexing_writer))
 
         commands.start_indexing_topology(env)
 
@@ -138,26 +132,50 @@ class Indexing(Script):
     def restart(self, env):
         from params import params
         env.set_params(params)
-
         self.configure(env)
         commands = IndexingCommands(params)
+
+        if params.ra_indexing_writer == 'Solr':
+            # Install Solr schemas
+            if not commands.is_solr_schema_installed():
+                if commands.solr_schema_install(env):
+                    commands.set_solr_schema_installed()
+
+        elif params.ra_indexing_writer == 'Elasticsearch':
+            # Install elasticsearch templates
+            if not commands.is_elasticsearch_template_installed():
+                if self.elasticsearch_template_install(env):
+                    commands.set_elasticsearch_template_installed()
+
+        else :
+            msg = "WARNING:  index schemas/templates could not be installed.  
" \
+                  "Is Indexing server configured properly ?  Will reattempt 
install on next start.  index server configured={0}"
+            Logger.warning(msg.format(params.ra_indexing_writer))
+
         commands.restart_indexing_topology(env)
 
     def elasticsearch_template_install(self, env):
         from params import params
         env.set_params(params)
         Logger.info("Installing Elasticsearch index templates")
-        metron_service.check_indexer_parameters()
 
-        commands = IndexingCommands(params)
-        for template_name, template_path in 
commands.get_templates().iteritems():
-
-            # install the index template
-            File(template_path, mode=0755, 
content=StaticFile("{0}.template".format(template_name)))
-            cmd = "curl -s -XPOST http://{0}/_template/{1} -d @{2}"
-            Execute(
-              cmd.format(params.es_http_url, template_name, template_path),
-              logoutput=True)
+        try:
+            metron_service.check_indexer_parameters()
+            commands = IndexingCommands(params)
+            for template_name, template_path in 
commands.get_templates().iteritems():
+                # install the index template
+                File(template_path, mode=0755, 
content=StaticFile("{0}.template".format(template_name)))
+                cmd = "curl -s -XPOST http://{0}/_template/{1} -d @{2}"
+                Execute(
+                  cmd.format(params.es_http_url, template_name, template_path),
+                  logoutput=True)
+            return True
+
+        except Exception as e:
+            msg = "WARNING: Elasticsearch index templates could not be 
installed.  " \
+                  "Is Elasticsearch running?  Will reattempt install on next 
start.  error={0}"
+            Logger.warning(msg.format(e))
+            return False
 
     def elasticsearch_template_delete(self, env):
         from params import params

Reply via email to