def create_collection(self, name, fields, unique_key_field='id', df='text'): """ Create solr collection or core and instance dir. Create schema.xml file so that we can set UniqueKey field. """ if self.is_solr_cloud_mode(): # solrcloud mode # Need to remove path afterwards tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, True) # Create instance directory. solrctl_path = get_solrctl_path() process = subprocess.Popen([solrctl_path, "--zk", ENSEMBLE.get(), "instancedir", "--create", name, solr_config_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) status = process.wait() # Don't want directories laying around shutil.rmtree(tmp_path) if status != 0: LOG.error("Could not create instance directory.\nOutput: %s\nError: %s" % process.communicate()) raise PopupException(_('Could not create instance directory. ' 'Check if [libzookeeper]ensemble and [indexer]solrctl_path are correct in Hue config.')) api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()) if not api.create_collection(name): # Delete instance directory if we couldn't create a collection. process = subprocess.Popen([solrctl_path, "--zk", ENSEMBLE.get(), "instancedir", "--delete", name], stdout=subprocess.PIPE, stderr=subprocess.PIPE) if process.wait() != 0: LOG.error("Cloud not delete collection.\nOutput: %s\nError: %s" % process.communicate()) raise PopupException(_('Could not create collection. Check error logs for more info.')) else: # Non-solrcloud mode # Create instance directory locally. instancedir = os.path.join(CORE_INSTANCE_DIR.get(), name) if os.path.exists(instancedir): raise PopupException(_("Instance directory %s already exists! Please remove it from the file system.") % instancedir) tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, False) shutil.move(solr_config_path, instancedir) shutil.rmtree(tmp_path) api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()) if not api.create_core(name, instancedir): # Delete instance directory if we couldn't create a collection. shutil.rmtree(instancedir) raise PopupException(_('Could not create collection. Check error logs for more info.'))
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 __init__(self, hosts=None, read_only=True): self.hosts = hosts if hosts else ENSEMBLE.get() self.read_only = read_only hdfs = cluster.get_hdfs() if hdfs is None: raise ZookeeperConfigurationException('No [hdfs] configured in hue.ini.') if hdfs.security_enabled: self.sasl_server_principal = PRINCIPAL_NAME.get() else: self.sasl_server_principal = None self.zk = KazooClient(hosts=self.hosts, read_only=self.read_only, sasl_server_principal=self.sasl_server_principal)
def delete_collection(self, name, core): """ Delete solr collection/core and instance dir """ api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get()) if core: raise PopupException(_('Cannot remove Solr cores.')) if api.remove_collection(name): # Delete instance directory. solrctl_path = get_solrctl_path() process = subprocess.Popen([solrctl_path, "--zk", ENSEMBLE.get(), "instancedir", "--delete", name], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) if process.wait() != 0: LOG.error("Cloud not delete instance directory.\nOutput stream: %s\nError stream: %s" % process.communicate()) raise PopupException(_('Could not create instance directory. Check error logs for more info.')) else: raise PopupException(_('Could not remove collection. Check error logs for more info.'))
def test_get_ensemble(self): clear = ENSEMBLE.set_for_testing("zoo:2181") try: assert_equal("zoo:2181", ENSEMBLE.get()) finally: clear() clear = ENSEMBLE.set_for_testing("zoo:2181,zoo2:2181") try: assert_equal("zoo:2181,zoo2:2181", ENSEMBLE.get()) finally: clear() clear = ENSEMBLE.set_for_testing(["zoo:2181", "zoo2:2181"]) try: assert_equal("zoo:2181,zoo2:2181", ENSEMBLE.get()) finally: clear()
def test_get_ensemble(self): clear = ENSEMBLE.set_for_testing('zoo:2181') try: assert_equal('zoo:2181', ENSEMBLE.get()) finally: clear() clear = ENSEMBLE.set_for_testing('zoo:2181,zoo2:2181') try: assert_equal('zoo:2181,zoo2:2181', ENSEMBLE.get()) finally: clear() clear = ENSEMBLE.set_for_testing(['zoo:2181', 'zoo2:2181']) try: assert_equal('zoo:2181,zoo2:2181', ENSEMBLE.get()) finally: clear()
def get_solr_ensemble(): return '%s/solr' % ENSEMBLE.get()
def get_solr_ensemble(): return '%s%s' % (ENSEMBLE.get(), SOLR_ZK_PATH.get())