예제 #1
0
    def _create_non_solr_cloud_index(self, name, fields, unique_key_field, df):
        # 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)

        try:
            tmp_path, solr_config_path = copy_configs(fields, unique_key_field,
                                                      df, False)
            try:
                shutil.move(solr_config_path, instancedir)
            finally:
                shutil.rmtree(tmp_path)

            if not self.api.create_core(name, instancedir):
                raise Exception('Failed to create core: %s' % name)
        except Exception as e:
            raise PopupException(
                _('Could not create index. Check error logs for more info.'),
                detail=e)
        finally:
            shutil.rmtree(instancedir)
예제 #2
0
파일: controller.py 프로젝트: zhxing/hue
  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", get_solr_ensemble(), "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", get_solr_ensemble(), "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.'))
예제 #3
0
  def _create_non_solr_cloud_collection(self, name, fields, unique_key_field, df):
    # 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)
    try:
      shutil.move(solr_config_path, instancedir)
    finally:
      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.'))
예제 #4
0
  def _create_non_solr_cloud_index(self, name, fields, unique_key_field, df):
    # 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)

    try:
      tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, False)
      try:
        shutil.move(solr_config_path, instancedir)
      finally:
        shutil.rmtree(tmp_path)

      if not self.api.create_core(name, instancedir):
        raise Exception('Failed to create core: %s' % name)
    except Exception, e:
      raise PopupException(_('Could not create index. Check error logs for more info.'), detail=e)
예제 #5
0
    def _create_non_solr_cloud_collection(self, name, fields, unique_key_field,
                                          df):
        # 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)
        try:
            shutil.move(solr_config_path, instancedir)
        finally:
            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.'
                  ))
예제 #6
0
        zc.copy_path(root_node, config_root_path)

        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:
        # Remove tmp config directory
        shutil.rmtree(tmp_path)

    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)

      try:
        tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, False)
        shutil.move(solr_config_path, instancedir)
        shutil.rmtree(tmp_path)

        if not self.api.create_core(name, instancedir):
          raise Exception('Failed to create core: %s' % name)
      except Exception, e:
        raise PopupException(_('Could not create index. Check error logs for more info.'), detail=e)
      finally:
        # Delete instance directory if we couldn't create the core.
예제 #7
0
        raise PopupException(_('Error in copying Solr configurations.'), detail=e)

      # Don't want directories laying around
      shutil.rmtree(tmp_path)

      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.
        try:
          zc.delete_path(root_node)
        except Exception, e:
          raise PopupException(_('Error in deleting Solr configurations.'), detail=e)
    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 delete_collection(self, name, core):
    """
    Delete solr collection/core and instance dir