def test_get_ensemble(): clear = ENSEMBLE.set_for_testing('zoo:2181') try: assert_equal('zoo:2181/solr', get_solr_ensemble()) finally: clear() clear = ENSEMBLE.set_for_testing('zoo:2181,zoo2:2181') try: assert_equal('zoo:2181,zoo2:2181/solr', get_solr_ensemble()) finally: clear()
def _create_solr_cloud_index(self, name, fields, unique_key_field, df): with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc: tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, True) try: root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name) config_root_path = '%s/%s' % (solr_config_path, 'conf') zc.copy_path(root_node, config_root_path) if is_enabled(): with open( os.path.join(config_root_path, 'solrconfig.xml.secure')) as f: zc.set( os.path.join(root_node, 'conf', 'solrconfig.xml'), f.read()) if not self.api.create_collection(name): raise Exception('Failed to create collection: %s' % name) except Exception, e: if zc.path_exists(root_node): # Remove the root node from Zookeeper zc.delete_path(root_node) raise PopupException(_( 'Could not create index. Check error logs for more info.'), detail=e) finally:
def delete_index(self, name): """ Delete solr collection/core and instance dir """ # TODO: Implement deletion of local Solr cores if not self.is_solr_cloud_mode(): raise PopupException(_("Cannot remove non-Solr cloud cores.")) if self.api.remove_collection(name): # Delete instance directory. try: root_node = "%s/%s" % (ZK_SOLR_CONFIG_NAMESPACE, name) with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc: zc.delete_path(root_node) except Exception, e: # Re-create collection so that we don't have an orphan config self.api.add_collection(name) raise PopupException(_("Error in deleting Solr configurations."), detail=e)
def delete_index(self, name): """ Delete solr collection/core and instance dir """ # TODO: Implement deletion of local Solr cores if not self.is_solr_cloud_mode(): raise PopupException(_('Cannot remove non-Solr cloud cores.')) if self.api.remove_collection(name): # Delete instance directory. try: root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name) with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc: zc.delete_path(root_node) except Exception, e: # Re-create collection so that we don't have an orphan config self.api.add_collection(name) raise PopupException( _('Error in deleting Solr configurations.'), detail=e)
def _create_solr_cloud_index(self, name, fields, unique_key_field, df): with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc: tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, True) try: root_node = "%s/%s" % (ZK_SOLR_CONFIG_NAMESPACE, name) config_root_path = "%s/%s" % (solr_config_path, "conf") zc.copy_path(root_node, config_root_path) if is_enabled(): with open(os.path.join(config_root_path, "solrconfig.xml.secure")) as f: zc.set(os.path.join(root_node, "conf", "solrconfig.xml"), f.read()) if not self.api.create_collection(name): raise Exception("Failed to create collection: %s" % name) except Exception, e: if zc.path_exists(root_node): # Remove the root node from Zookeeper zc.delete_path(root_node) raise PopupException(_("Could not create index. Check error logs for more info."), detail=e) finally: