Esempio n. 1
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():
      # 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)

      if not self.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)
Esempio n. 2
0
    def create_index(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():
            tmp_path, solr_config_path = copy_configs(fields, unique_key_field,
                                                      df, True)

            try:
                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')
                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:
Esempio n. 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)
Esempio n. 4
0
  def test_copy_and_delete_path(self):
    root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_copy_and_delete_path')
    client = ZookeeperClient(hosts=zkensemble(), read_only=False)

    # Test copy_path
    client.copy_path(root_node, TestWithZooKeeper.local_directory)

    client.zk.start()
    try:
      assert_true(client.zk.exists('%s' % root_node))
      assert_true(client.zk.exists('%s/%s' % (root_node, TestWithZooKeeper.subdir_name)))
      assert_true(client.zk.exists('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename)))
      contents, stats = client.zk.get('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename))
      assert_equal(contents, TestWithZooKeeper.file_contents)
    finally:
      client.zk.stop()

    # Test delete_path
    client.delete_path(root_node)

    client.zk.start()
    try:
      assert_equal(client.zk.exists('%s' % root_node), None)
      assert_equal(client.zk.exists('%s/%s' % (root_node, TestWithZooKeeper.subdir_name)), None)
      assert_equal(client.zk.exists('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename)), None)
    finally:
      client.zk.stop()
Esempio n. 5
0
  def test_copy_and_delete_path(self):
    root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_copy_and_delete_path')
    client = ZookeeperClient(hosts=zkensemble(), read_only=False)

    # Delete the root_node first just in case it wasn't cleaned up in previous run
    client.zk.start()
    client.zk.delete(root_node, recursive=True)
    client.zk.stop()

    # Test copy_path
    client.copy_path(root_node, TestWithZooKeeper.local_directory)

    client.zk.start()
    assert_true(client.zk.exists('%s' % root_node))
    assert_true(client.zk.exists('%s/%s' % (root_node, TestWithZooKeeper.subdir_name)))
    assert_true(client.zk.exists('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename)))
    contents, stats = client.zk.get('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename))
    assert_equal(contents, TestWithZooKeeper.file_contents)
    client.zk.stop()

    # Test delete_path
    client.delete_path(root_node)

    client.zk.start()
    assert_equal(client.zk.exists('%s' % root_node), None)
    assert_equal(client.zk.exists('%s/%s' % (root_node, TestWithZooKeeper.subdir_name)), None)
    assert_equal(client.zk.exists('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename)), None)
Esempio n. 6
0
 def delete_collection(self, name):
   if self.api.remove_collection(name):
     # Delete instance directory.
     try:
       root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)
       zc = ZookeeperClient(hosts=get_solr_ensemble(), read_only=False)
       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)
Esempio n. 7
0
 def delete_collection(self, name):
     if self.api.remove_collection(name):
         # Delete instance directory.
         try:
             root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)
             zc = ZookeeperClient(hosts=get_solr_ensemble(),
                                  read_only=False)
             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)
Esempio n. 8
0
  def test_path_exists(self):
    try:
      root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_path_exists')
      client = ZookeeperClient(hosts=zkensemble(), read_only=False)

      # Delete the root_node first just in case it wasn't cleaned up in previous run
      client.zk.start()
      client.zk.create(root_node, value='test_path_exists')
      client.zk.stop()

      assert_true(client.path_exists(namespace=root_node))
      assert_false(client.path_exists(namespace='bogus_path'))
    finally:
      client.delete_path(root_node)
Esempio n. 9
0
  def test_path_exists(self):
    root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_path_exists')
    client = ZookeeperClient(hosts=zkensemble(), read_only=False)

    client.zk.start()
    try:
      client.zk.create(root_node, value='test_path_exists', makepath=True)

      try:
        assert_true(client.path_exists(namespace=root_node))
        assert_false(client.path_exists(namespace='bogus_path'))
      finally:
        client.delete_path(root_node)
    finally:
      client.zk.stop()
Esempio n. 10
0
    def test_path_exists(self):
        root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_path_exists')
        client = ZookeeperClient(hosts=zkensemble(), read_only=False)

        client.zk.start()
        try:
            client.zk.create(root_node,
                             value='test_path_exists',
                             makepath=True)

            try:
                assert_true(client.path_exists(namespace=root_node))
                assert_false(client.path_exists(namespace='bogus_path'))
            finally:
                client.delete_path(root_node)
        finally:
            client.zk.stop()
Esempio n. 11
0
  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)
        zc = ZookeeperClient(hosts=get_solr_ensemble(), read_only=False)
        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)
Esempio n. 12
0
  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.
      try:
        root_node = '%s/%s' % (ZK_SOLR_CONFIG_NAMESPACE, name)
        zc = ZookeeperClient(hosts=get_solr_ensemble(), read_only=False)
        zc.delete_path(root_node)
      except Exception, e:
        # Re-create collection so that we don't have an orphan config
        api.add_collection(name)
        raise PopupException(_('Error in deleting Solr configurations.'), detail=e)
Esempio n. 13
0
    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)
                zc = ZookeeperClient(hosts=get_solr_ensemble(),
                                     read_only=False)
                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)
Esempio n. 14
0
    def test_copy_and_delete_path(self):
        root_node = '%s/%s' % (TestWithZooKeeper.namespace,
                               'test_copy_and_delete_path')
        client = ZookeeperClient(hosts=zkensemble(), read_only=False)

        # Test copy_path
        client.copy_path(root_node, TestWithZooKeeper.local_directory)

        client.zk.start()
        try:
            assert_true(client.zk.exists('%s' % root_node))
            assert_true(
                client.zk.exists('%s/%s' %
                                 (root_node, TestWithZooKeeper.subdir_name)))
            assert_true(
                client.zk.exists('%s/%s/%s' %
                                 (root_node, TestWithZooKeeper.subdir_name,
                                  TestWithZooKeeper.filename)))
            contents, stats = client.zk.get(
                '%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name,
                              TestWithZooKeeper.filename))
            assert_equal(contents, TestWithZooKeeper.file_contents)
        finally:
            client.zk.stop()

        # Test delete_path
        client.delete_path(root_node)

        client.zk.start()
        try:
            assert_equal(client.zk.exists('%s' % root_node), None)
            assert_equal(
                client.zk.exists('%s/%s' %
                                 (root_node, TestWithZooKeeper.subdir_name)),
                None)
            assert_equal(
                client.zk.exists('%s/%s/%s' %
                                 (root_node, TestWithZooKeeper.subdir_name,
                                  TestWithZooKeeper.filename)), None)
        finally:
            client.zk.stop()
Esempio n. 15
0
    def test_copy_and_delete_path(self):
        root_node = '%s/%s' % (TestWithZooKeeper.namespace,
                               'test_copy_and_delete_path')
        client = ZookeeperClient(hosts=zkensemble(), read_only=False)

        # Delete the root_node first just in case it wasn't cleaned up in previous run
        client.zk.start()
        client.zk.delete(root_node, recursive=True)
        client.zk.stop()

        # Test copy_path
        client.copy_path(root_node, TestWithZooKeeper.local_directory)

        client.zk.start()
        assert_true(client.zk.exists('%s' % root_node))
        assert_true(
            client.zk.exists('%s/%s' %
                             (root_node, TestWithZooKeeper.subdir_name)))
        assert_true(
            client.zk.exists('%s/%s/%s' %
                             (root_node, TestWithZooKeeper.subdir_name,
                              TestWithZooKeeper.filename)))
        contents, stats = client.zk.get(
            '%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name,
                          TestWithZooKeeper.filename))
        assert_equal(contents, TestWithZooKeeper.file_contents)
        client.zk.stop()

        # Test delete_path
        client.delete_path(root_node)

        client.zk.start()
        assert_equal(client.zk.exists('%s' % root_node), None)
        assert_equal(
            client.zk.exists('%s/%s' %
                             (root_node, TestWithZooKeeper.subdir_name)), None)
        assert_equal(
            client.zk.exists('%s/%s/%s' %
                             (root_node, TestWithZooKeeper.subdir_name,
                              TestWithZooKeeper.filename)), None)
Esempio n. 16
0
  def create_index(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():
      tmp_path, solr_config_path = copy_configs(fields, unique_key_field, df, True)

      try:
        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')
        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: