예제 #1
0
  def _create_solr_cloud_collection(self, name, fields, unique_key_field, df):
    with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc:
      root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)

      tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, True)
      try:
        config_root_path = '%s/%s' % (solr_config_path, 'conf')
        try:
          zc.copy_path(root_node, config_root_path)

        except Exception, e:
          zc.delete_path(root_node)
          raise PopupException(_('Error in copying Solr configurations.'), detail=e)
      finally:
        # 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)
        raise PopupException(_('Could not create collection. Check error logs for more info.'))
예제 #2
0
    def _create_solr_cloud_collection(self, name, fields, unique_key_field,
                                      df):
        with ZookeeperClient(hosts=get_solr_ensemble(), read_only=False) as zc:
            root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)

            tmp_path, solr_config_path = copy_configs(fields, unique_key_field,
                                                      df, True)
            try:
                config_root_path = '%s/%s' % (solr_config_path, 'conf')
                try:
                    zc.copy_path(root_node, config_root_path)
                except Exception, e:
                    zc.delete_path(root_node)
                    raise PopupException(
                        _('Error in copying Solr configurations.'), detail=e)
            finally:
                # 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)
                raise PopupException(
                    _('Could not create collection. Check error logs for more info.'
                      ))
예제 #3
0
  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)

      zc = ZookeeperClient(hosts=get_solr_ensemble(), read_only=False)
      root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)
      config_root_path = '%s/%s' % (solr_config_path, 'conf')
      try:
        zc.copy_path(root_node, config_root_path)
      except Exception, e:
        zc.delete_path(root_node)
        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)
예제 #4
0
  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 = utils.copy_configs(fields, unique_key_field, df, True)

      # Create instance directory.
      solrctl_path = get_solrctl_path()

      process = subprocess.Popen([solrctl_path, "instancedir", "--create", name, solr_config_path],
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 env={
                                   'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
                                 })
      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 solr_zk_ensemble and solrctl_path are correct in Hue config [indexer].'))

      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, "instancedir", "--delete", name],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   env={
                                     'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
                                   })
        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(conf.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 = utils.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.'))
예제 #5
0
파일: controller.py 프로젝트: onimsha/hue
    def create_collection(self,
                          name,
                          fields,
                          unique_key_field='id',
                          df='text'):
        """
    Create solr collection and instance dir.
    Create schema.xml file so that we can set UniqueKey field.
    """
        # Need to remove path afterwards
        tmp_path, solr_config_path = utils.copy_configs(
            fields, unique_key_field, df)

        # Create instance directory.
        process = subprocess.Popen(
            [
                conf.SOLRCTL_PATH.get(), "instancedir", "--create", name,
                solr_config_path
            ],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            env={
                'SOLR_HOME': conf.SOLR_HOME.get(),
                'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
            })
        status = process.wait()
        shutil.rmtree(tmp_path)

        if status != 0:
            LOG.error(
                "Cloud not create instance directory.\nOutput stream: %s\nError stream: %s"
                % process.communicate())
            raise PopupException(
                _('Could not create instance directory. Check error logs for more info.'
                  ))

        api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())

        if not api.create_collection(name):
            # Delete instance directory.
            process = subprocess.Popen(
                [conf.SOLRCTL_PATH.get(), "instancedir", "--delete", name],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                env={
                    'SOLR_HOME': conf.SOLR_HOME.get(),
                    'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
                })

            if process.wait() != 0:
                LOG.error(
                    "Cloud not delete instance directory.\nOutput stream: %s\nError stream: %s"
                    % process.communicate())
            raise PopupException(
                _('Could not create collection. Check error logs for more info.'
                  ))
예제 #6
0
파일: controller.py 프로젝트: CrazyJvm/hue
  def create_collection(self, name, fields, unique_key_field='id', df='text'):
    """
    Create solr collection and instance dir.
    Create schema.xml file so that we can set UniqueKey field.
    """
    # Need to remove path afterwards
    tmp_path, solr_config_path = utils.copy_configs(fields, unique_key_field, df)

    # Create instance directory.
    process = subprocess.Popen([conf.SOLRCTL_PATH.get(), "instancedir", "--create", name, solr_config_path],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               env={
                                 'SOLR_HOME': conf.SOLR_HOME.get(),
                                 'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
                               })
    status = process.wait()
    shutil.rmtree(tmp_path)

    if status != 0:
      LOG.error("Cloud not create instance directory.\nOutput stream: %s\nError stream: %s" % process.communicate())
      raise PopupException(_('Could not create instance directory. Check error logs for more info.'))

    api = SolrApi(SOLR_URL.get(), self.user, SECURITY_ENABLED.get())

    if not api.create_collection(name):
      # Delete instance directory.
      process = subprocess.Popen([conf.SOLRCTL_PATH.get(), "instancedir", "--delete", name],
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 env={
                                   'SOLR_HOME': conf.SOLR_HOME.get(),
                                   'SOLR_ZK_ENSEMBLE': conf.SOLR_ZK_ENSEMBLE.get()
                                 })

      if process.wait() != 0:
        LOG.error("Cloud not delete instance directory.\nOutput stream: %s\nError stream: %s" % process.communicate())
      raise PopupException(_('Could not create collection. Check error logs for more info.'))