Ejemplo n.º 1
0
    def __init__(self, host='127.0.0.1', port=8098, prefix='riak',
                 mapred_prefix='mapred', transport_class=None,
                 client_id=None, solr_transport_class=None,
                 bucket_class_factory=None):
        """
        Construct a new ``RiakClient`` object.

        :param host: Hostname or IP address
        :type host: string
        :param port: Port number
        :type port: integer
        :param prefix: Interface prefix
        :type prefix: string
        :param mapred_prefix: MapReduce prefix
        :type mapred_prefix: string
        :param transport_class: Transport class to use
        :type transport_class: :class:`RiakTransport`
        :param solr_transport_class: HTTP-based transport class for Solr interface queries
        :param bucket_class_factory: Callable that given a bucket name returns a class to use
        :type bucket_class_factory: callable
        """
        if transport_class is None:
            transport_class = RiakHttpTransport

        if callable(bucket_class_factory):
            self.bucket_class_factory = bucket_class_factory
        else:
            self.bucket_class_factory = lambda name: RiakBucket

        api = getattr(transport_class, 'api', 1)
        if api >= 2:
            hostports = [ (host, port), ]
            self._cm = transport_class.default_cm(hostports)

            ### we need to allow additional transport options. make this an
            ### argument to __init__ ?
            transport_options = { }

            self._transport = transport_class(self._cm,
                                              prefix=prefix,
                                              mapred_prefix=mapred_prefix,
                                              client_id=client_id,
                                              **transport_options)
        else:
            deprecated('please upgrade the transport to the new API')
            self._cm = None
            self._transport = transport_class(host, port, client_id=client_id)

        self._r = "default"
        self._w = "default"
        self._dw = "default"
        self._rw = "default"
        self._encoders = {'application/json':json.dumps,
                          'text/json':json.dumps}
        self._decoders = {'application/json':json.loads,
                          'text/json':json.loads}
        self._solr = None
        self._host = host
        self._port = port
Ejemplo n.º 2
0
    def __init__(self,
                 protocol='http',
                 transport_options={},
                 nodes=None,
                 **unused_args):
        """
        Construct a new ``RiakClient`` object.

        :param protocol: the preferred protocol, defaults to 'http'
        :type protocol: string
        :param nodes: a list of node configurations,
           where each configuration is a dict containing the keys
           'host', 'http_port', and 'pb_port'
        :type nodes: list
        :param transport_options: Optional key-value args to pass to
                                  the transport constructor
        :type transport_options: dict
        """
        unused_args = unused_args.copy()

        if 'port' in unused_args:
            deprecated("port option is deprecated, use http_port or pb_port,"
                       " or the nodes option. Your given port of %r will be "
                       "used as the %s port unless already set" %
                       (unused_args['port'], protocol))
            unused_args['already_warned_port'] = True
            if (protocol in ['http', 'https']
                    and 'http_port' not in unused_args):
                unused_args['http_port'] = unused_args['port']
            elif protocol == 'pbc' and 'pb_port' not in unused_args:
                unused_args['pb_port'] = unused_args['port']

        if 'transport_class' in unused_args:
            deprecated(
                "transport_class is deprecated, use the protocol option")

        if nodes is None:
            self.nodes = [
                self._create_node(unused_args),
            ]
        else:
            self.nodes = [self._create_node(n) for n in nodes]

        self.protocol = protocol or 'http'
        self.resolver = default_resolver
        self._http_pool = RiakHttpPool(self, **transport_options)
        self._pb_pool = RiakPbcPool(self, **transport_options)

        self._encoders = {
            'application/json': default_encoder,
            'text/json': default_encoder,
            'text/plain': str
        }
        self._decoders = {
            'application/json': default_decoder,
            'text/json': default_decoder,
            'text/plain': str
        }
        self._buckets = WeakValueDictionary()
Ejemplo n.º 3
0
 def get_transport(self):
     """
     Get the transport instance the client is using for it's
     connection. DEPRECATED
     """
     deprecated("get_transport is deprecated, use client, " +
                "bucket, or object methods instead")
     return None
Ejemplo n.º 4
0
    def __init__(self, host='127.0.0.1', port=8098, prefix='riak',
                 mapred_prefix='mapred', transport_class=None,
                 client_id=None, solr_transport_class=None,
                 transport_options=None):
        """
        Construct a new ``RiakClient`` object.

        :param host: Hostname or IP address
        :type host: string
        :param port: Port number
        :type port: integer
        :param prefix: Interface prefix
        :type prefix: string
        :param mapred_prefix: MapReduce prefix
        :type mapred_prefix: string
        :param transport_class: transport class to use
        :type transport_class: :class:`RiakTransport`
        :param solr_transport_class: HTTP-based transport class for Solr interface queries
        :type transport_class: :class:`RiakHttpTransport`
        :param transport_options: Optional key-value args to pass to the transport constuctor
        :type transport_options: dict
        """
        if transport_class is None:
            transport_class = RiakHttpTransport

        api = getattr(transport_class, 'api', 1)
        if api >= 2:
            hostports = [ (host, port), ]
            self._cm = transport_class.default_cm(hostports)

            # If no transport options are provided, then default to the
            # empty dict, otherwise just pass through what we are provided.
            if transport_options is None:
                transport_options = {}

            self._transport = transport_class(self._cm,
                                              prefix=prefix,
                                              mapred_prefix=mapred_prefix,
                                              client_id=client_id,
                                              **transport_options)
        else:
            deprecated('please upgrade the transport to the new API')
            self._cm = None
            self._transport = transport_class(host, port, client_id=client_id)

        self._r = "default"
        self._w = "default"
        self._dw = "default"
        self._rw = "default"
        self._pr = "default"
        self._pw = "default"
        self._encoders = {'application/json': json.dumps,
                          'text/json': json.dumps}
        self._decoders = {'application/json': json.loads,
                          'text/json': json.loads}
        self._solr = None
        self._host = host
        self._port = port
Ejemplo n.º 5
0
    def solr(self):
        """
        Returns a RiakSearch object which can access search indexes.

        .. deprecated:: 2.0.0
           Use the ``fulltext_*`` methods instead.
        """
        deprecated("``solr`` is deprecated, use ``fulltext_search``,"
                   " ``fulltext_add`` and ``fulltext_delete`` directly")
        return RiakSearch(self)
Ejemplo n.º 6
0
    def solr(self):
        """
        Returns a RiakSearch object which can access search indexes.

        .. deprecated:: 2.0.0
           Use the ``fulltext_*`` methods instead.
        """
        deprecated("``solr`` is deprecated, use ``fulltext_search``,"
                   " ``fulltext_add`` and ``fulltext_delete`` directly")
        return RiakSearch(self)
Ejemplo n.º 7
0
    def get_client_id(self):
        """
        Get the ``client_id`` for this ``RiakClient`` instance.
        DEPRECATED

        :rtype: string
        """
        deprecated(
            "``get_client_id`` is deprecated, use the ``client_id`` property")
        return self.client_id
Ejemplo n.º 8
0
    def __init__(self, protocol='http', transport_options={}, nodes=None,
                 credentials=None, **unused_args):
        """
        Construct a new ``RiakClient`` object.

        :param protocol: the preferred protocol, defaults to 'http'
        :type protocol: string
        :param nodes: a list of node configurations,
           where each configuration is a dict containing the keys
           'host', 'http_port', and 'pb_port'
        :type nodes: list
        :param transport_options: Optional key-value args to pass to
                                  the transport constructor
        :type transport_options: dict
        :param credentials: optional object of security info
        :type credentials: SecurityCreds or dict
        """
        unused_args = unused_args.copy()

        if 'port' in unused_args:
            deprecated("port option is deprecated, use http_port or pb_port,"
                       " or the nodes option. Your given port of %r will be "
                       "used as the %s port unless already set" %
                       (unused_args['port'], protocol))
            unused_args['already_warned_port'] = True
            if (protocol == 'http' and
                    'http_port' not in unused_args):
                unused_args['http_port'] = unused_args['port']
            elif protocol == 'pbc' and 'pb_port' not in unused_args:
                unused_args['pb_port'] = unused_args['port']

        if 'transport_class' in unused_args:
            deprecated(
                "transport_class is deprecated, use the protocol option")

        if nodes is None:
            self.nodes = [self._create_node(unused_args), ]
        else:
            self.nodes = [self._create_node(n) for n in nodes]

        self.protocol = protocol or 'http'
        self.resolver = default_resolver
        self._credentials = self._create_credentials(credentials)
        self._http_pool = RiakHttpPool(self, **transport_options)
        self._pb_pool = RiakPbcPool(self, **transport_options)

        self._encoders = {'application/json': default_encoder,
                          'text/json': default_encoder,
                          'text/plain': str}
        self._decoders = {'application/json': json.loads,
                          'text/json': json.loads,
                          'text/plain': str}
        self._buckets = WeakValueDictionary()
        self._bucket_types = WeakValueDictionary()
Ejemplo n.º 9
0
    def get_transport(self):
        """
        Get the transport instance the client is using for it's
        connection.

        .. deprecated:: 2.0.0
           There is no equivalent to this method, it will return ``None``.
        """
        deprecated("get_transport is deprecated, use client, " +
                   "bucket, or object methods instead")
        return None
Ejemplo n.º 10
0
    def get_transport(self):
        """
        Get the transport instance the client is using for it's
        connection.

        .. deprecated:: 2.0.0
           There is no equivalent to this method, it will return ``None``.
        """
        deprecated("get_transport is deprecated, use client, " +
                   "bucket, or object methods instead")
        return None
Ejemplo n.º 11
0
    def get_client_id(self):
        """
        Get the client identifier.

        .. deprecated:: 2.0.0
           Use the :attr:`client_id` attribute instead.

        :rtype: string
        """
        deprecated(
            "``get_client_id`` is deprecated, use the ``client_id`` property")
        return self.client_id
Ejemplo n.º 12
0
    def get_client_id(self):
        """
        Get the client identifier.

        .. deprecated:: 2.0.0
           Use the :attr:`client_id` attribute instead.

        :rtype: string
        """
        deprecated(
            "``get_client_id`` is deprecated, use the ``client_id`` property")
        return self.client_id
Ejemplo n.º 13
0
    def set_client_id(self, client_id):
        """
        Set the client_id for this ``RiakClient`` instance.
        DEPRECATED

        :param client_id: The new client_id.
        :type client_id: string
        """
        deprecated(
            "``set_client_id`` is deprecated, use the ``client_id`` property")
        self.client_id = client_id
        return self
Ejemplo n.º 14
0
    def set_client_id(self, client_id):
        """
        Set the client identifier.

        .. deprecated:: 2.0.0
           Use the :attr:`client_id` attribute instead.

        :param client_id: The new client_id.
        :type client_id: string
        """
        deprecated(
            "``set_client_id`` is deprecated, use the ``client_id`` property")
        self.client_id = client_id
        return self
Ejemplo n.º 15
0
    def set_client_id(self, client_id):
        """
        Set the client identifier.

        .. deprecated:: 2.0.0
           Use the :attr:`client_id` attribute instead.

        :param client_id: The new client_id.
        :type client_id: string
        """
        deprecated(
            "``set_client_id`` is deprecated, use the ``client_id`` property")
        self.client_id = client_id
        return self
Ejemplo n.º 16
0
    def get_binary(self, key, r=None, pr=None):
        """
        Retrieve a binary/string object from Riak.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        deprecated('RiakBucket.get_binary is deprecated, '
                   'use RiakBucket.get')
        return self.get(key, r=r, pr=pr)
Ejemplo n.º 17
0
    def get_binary(self, key, r=None, pr=None):
        """
        Retrieve a binary/string object from Riak.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        deprecated('RiakBucket.get_binary is deprecated, '
                   'use RiakBucket.get')
        return self.get(key, r=r, pr=pr)
Ejemplo n.º 18
0
    def new_binary_from_file(self, key, filename):
        """
        Create a new Riak object in the bucket, using the contents of
        the specified file. This is a shortcut for :meth:`new`, where the
        ``encoded_data`` and ``content_type`` are set for you.

        .. deprecated:: 2.0.0
           Use :meth:`new_from_file` instead.

        :param key: the key of the new object
        :type key: string
        :param filename: the file to read the contents from
        :type filename: string
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        deprecated('RiakBucket.new_binary_from_file is deprecated, use '
                   'RiakBucket.new_from_file')
        return self.new_from_file(key, filename)
Ejemplo n.º 19
0
    def new_binary_from_file(self, key, filename):
        """
        Create a new Riak object in the bucket, using the contents of
        the specified file. This is a shortcut for :meth:`new`, where the
        ``encoded_data`` and ``content_type`` are set for you.

        .. deprecated:: 2.0.0
           Use :meth:`new_from_file` instead.

        :param key: the key of the new object
        :type key: string
        :param filename: the file to read the contents from
        :type filename: string
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        deprecated('RiakBucket.new_binary_from_file is deprecated, use '
                   'RiakBucket.new_from_file')
        return self.new_from_file(key, filename)
Ejemplo n.º 20
0
    def get_binary(self, key, r=None, pr=None, timeout=None):
        """
        Retrieve a binary/string object from Riak.

        .. deprecated:: 2.0.0
           Use :meth:`get` instead.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :param timeout: a timeout value in milliseconds
        :type timeout: int
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        deprecated('RiakBucket.get_binary is deprecated, '
                   'use RiakBucket.get')
        return self.get(key, r=r, pr=pr, timeout=timeout)
Ejemplo n.º 21
0
    def new_binary(self, key=None, data=None,
                   content_type='application/octet-stream'):
        """
        Create a new :class:`RiakObject <riak.riak_object.RiakObject>`
        that will be stored as plain text/binary. A shortcut for
        manually instantiating a :class:`RiakObject
        <riak.riak_object.RiakObject>`.

        :param key: Name of the key.
        :type key: string
        :param data: The data to store.
        :type data: object
        :param content_type: The content type of the object.
        :type content_type: string
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        deprecated('RiakBucket.new_binary is deprecated, '
                   'use RiakBucket.new with the encoded_data '
                   'param instead of data')
        return self.new(key, encoded_data=data, content_type=content_type)
Ejemplo n.º 22
0
    def __init__(self, host='127.0.0.1', http_port=8098, pb_port=8087,
                 **unused_args):
        """
        Creates a node.

        :param host: an IP address or hostname
        :type host: string
        :param http_port: the HTTP port of the node
        :type http_port: integer
        :param pb_port: the Protcol Buffers port of the node
        :type pb_port: integer
        """

        if 'port' in unused_args and 'already_warned_port' not in unused_args:
            deprecated("port option is deprecated, use http_port or pb_port")

        self.host = host
        self.http_port = http_port
        self.pb_port = pb_port
        self.error_rate = Decaying()
Ejemplo n.º 23
0
    def get_binary(self, key, r=None, pr=None, timeout=None):
        """
        Retrieve a binary/string object from Riak.

        .. deprecated:: 2.0.0
           Use :meth:`get` instead.

        :param key: Name of the key.
        :type key: string
        :param r: R-Value of the request (defaults to bucket's R)
        :type r: integer
        :param pr: PR-Value of the request (defaults to bucket's PR)
        :type pr: integer
        :param timeout: a timeout value in milliseconds
        :type timeout: int
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        deprecated('RiakBucket.get_binary is deprecated, '
                   'use RiakBucket.get')
        return self.get(key, r=r, pr=pr, timeout=timeout)
Ejemplo n.º 24
0
    def new_binary(self,
                   key=None,
                   data=None,
                   content_type='application/octet-stream'):
        """
        Create a new :class:`RiakObject <riak.riak_object.RiakObject>`
        that will be stored as plain text/binary. A shortcut for
        manually instantiating a :class:`RiakObject
        <riak.riak_object.RiakObject>`.

        :param key: Name of the key.
        :type key: string
        :param data: The data to store.
        :type data: object
        :param content_type: The content type of the object.
        :type content_type: string
        :rtype: :class:`RiakObject <riak.riak_object.RiakObject>`
        """
        deprecated('RiakBucket.new_binary is deprecated, '
                   'use RiakBucket.new with the encoded_data '
                   'param instead of data')
        return self.new(key, encoded_data=data, content_type=content_type)
Ejemplo n.º 25
0
    def __init__(self, protocol='http', transport_options={},
                 nodes=None, **unused_args):
        """
        Construct a new ``RiakClient`` object.

        :param protocol: the preferred protocol, defaults to 'http'
        :type protocol: string
        :param nodes: a list of node configurations,
           where each configuration is a dict containing the keys
           'host', 'http_port', and 'pb_port'
        :type nodes: list
        :param transport_options: Optional key-value args to pass to
                                  the transport constuctor
        :type transport_options: dict
        """
        if 'port' in unused_args:
            deprecated("port option is deprecated, use http_port or pb_port,"
                      + " or the nodes option")

        if 'transport_class' in unused_args:
            deprecated(
                "transport_class is deprecated, use the protocol option")

        if nodes is None:
            self.nodes = [self._create_node(unused_args), ]
        else:
            self.nodes = [self._create_node(n) for n in nodes]

        self.protocol = protocol or 'http'

        self._http_pool = RiakHttpPool(self, **transport_options)
        self._pb_pool = RiakPbcPool(self, **transport_options)

        self._encoders = {'application/json': json.dumps,
                          'text/json': json.dumps}
        self._decoders = {'application/json': json.loads,
                          'text/json': json.loads}
        self._buckets = WeakValueDictionary()
Ejemplo n.º 26
0
    def __init__(self,
                 host='127.0.0.1',
                 http_port=8098,
                 pb_port=8087,
                 **unused_args):
        """
        Creates a node.

        :param host: an IP address or hostname
        :type host: string
        :param http_port: the HTTP port of the node
        :type http_port: integer
        :param pb_port: the Protcol Buffers port of the node
        :type pb_port: integer
        """

        if 'port' in unused_args and not 'already_warned_port' in unused_args:
            deprecated("port option is deprecated, use http_port or pb_port")

        self.host = host
        self.http_port = http_port
        self.pb_port = pb_port
        self.error_rate = Decaying()
Ejemplo n.º 27
0
 def get_sibling(self, index):
     deprecated("RiakObject.get_sibling is deprecated, use the "
                "siblings property instead")
     return self.siblings[index]
Ejemplo n.º 28
0
    def __init__(self,
                 host='127.0.0.1',
                 port=8098,
                 prefix='riak',
                 mapred_prefix='mapred',
                 transport_class=None,
                 client_id=None,
                 solr_transport_class=None,
                 transport_options=None):
        """
        Construct a new ``RiakClient`` object.

        :param host: Hostname or IP address
        :type host: string
        :param port: Port number
        :type port: integer
        :param prefix: Interface prefix
        :type prefix: string
        :param mapred_prefix: MapReduce prefix
        :type mapred_prefix: string
        :param transport_class: transport class to use
        :type transport_class: :class:`RiakTransport`

        :param solr_transport_class: HTTP-based transport class for
                                     Solr interface queries
        :type solr_transport_class: :class:`RiakHttpTransport`
        :param transport_options: Optional key-value args to pass to
                                  the transport constuctor
        :type transport_options: dict
        """
        if transport_class is None:
            transport_class = RiakHttpTransport

        api = getattr(transport_class, 'api', 1)
        if api >= 2:
            hostports = [
                (host, port),
            ]
            self._cm = transport_class.default_cm(hostports)

            # If no transport options are provided, then default to the
            # empty dict, otherwise just pass through what we are provided.
            if transport_options is None:
                transport_options = {}

            self._transport = transport_class(self._cm,
                                              prefix=prefix,
                                              mapred_prefix=mapred_prefix,
                                              client_id=client_id,
                                              **transport_options)
        else:
            deprecated('please upgrade the transport to the new API')
            self._cm = None
            self._transport = transport_class(host, port, client_id=client_id)

        self._r = "default"
        self._w = "default"
        self._dw = "default"
        self._rw = "default"
        self._pr = "default"
        self._pw = "default"
        self._encoders = {
            'application/json': json.dumps,
            'text/json': json.dumps
        }
        self._decoders = {
            'application/json': json.loads,
            'text/json': json.loads
        }
        self._solr = None
        self._host = host
        self._port = port
Ejemplo n.º 29
0
 def set_encoded_data(self, value):
     deprecated("`set_encoded_data` is deprecated, use the `encoded_data`"
                " property")
     self.encoded_data = value
Ejemplo n.º 30
0
 def get_encoded_data(self):
     deprecated("`get_encoded_data` is deprecated, use the `encoded_data`"
                " property")
     return self.encoded_data
Ejemplo n.º 31
0
 def get_encoded_data(self):
     deprecated("`get_encoded_data` is deprecated, use the `encoded_data`"
                " property")
     return self.encoded_data
Ejemplo n.º 32
0
 def set_encoded_data(self, value):
     deprecated("`set_encoded_data` is deprecated, use the `encoded_data`"
                " property")
     self.encoded_data = value
Ejemplo n.º 33
0
 def new_binary_from_file(self, key, filename):
     deprecated('RiakBucket.new_binary_from_file is deprecated, use '
                'RiakBucket.new_from_file')
     return self.new_from_file(key, filename)
Ejemplo n.º 34
0
 def new_binary_from_file(self, key, filename):
     deprecated('RiakBucket.new_binary_from_file is deprecated, use '
                'RiakBucket.new_from_file')
     return self.new_from_file(key, filename)
Ejemplo n.º 35
0
 def get_sibling(self, index):
     deprecated("RiakObject.get_sibling is deprecated, use the "
                "siblings property instead")
     return self.siblings[index]