예제 #1
0
    def connect(self, *args):
        """
        Connect to the server. Connection parameters may be either one node
        (host and port), or list (or other iterable) of nodes.

        :param host: Ignite server host,
        :param port: Ignite server port,
        :param nodes: iterable of (host, port) tuples.
        """
        self.nodes = iter([])
        if len(args) == 0:
            host, port = IGNITE_DEFAULT_HOST, IGNITE_DEFAULT_PORT
        elif len(args) == 1 and is_iterable(args[0]):
            self.nodes = iter(args[0])
            host, port = next(self.nodes)
        elif (
            len(args) == 2
            and isinstance(args[0], str)
            and isinstance(args[1], int)
        ):
            host, port = args
        else:
            raise ConnectionError('Connection parameters are not valid.')

        self._connect(host, port)
예제 #2
0
    def map_python_type(cls, value):
        from pyignite.datatypes import (
            MapObject, ObjectArrayObject, BinaryObject,
        )

        if cls._python_map is None:
            cls._init_python_map()
        if cls._python_array_map is None:
            cls._init_python_array_map()

        value_type = type(value)
        if is_iterable(value) and value_type is not str:
            value_subtype = cls.get_subtype(value)
            if value_subtype in cls._python_array_map:
                return cls._python_array_map[value_subtype]

            # a little heuristics (order may be important)
            if all([
                value_subtype is None,
                len(value) == 2,
                isinstance(value[0], int),
                isinstance(value[1], dict),
            ]):
                return MapObject

            if all([
                value_subtype is None,
                len(value) == 2,
                isinstance(value[0], int),
                is_iterable(value[1]),
            ]):
                return ObjectArrayObject

            raise TypeError(
                'Type `array of {}` is invalid'.format(value_subtype)
            )

        if is_binary(value):
            return BinaryObject

        if value_type in cls._python_map:
            return cls._python_map[value_type]
        raise TypeError(
            'Type `{}` is invalid.'.format(value_type)
        )
예제 #3
0
    def map_python_type(cls, value):
        from pyignite.datatypes import (
            MapObject, ObjectArrayObject, BinaryObject,
        )

        if cls._python_map is None:
            cls._init_python_map()
        if cls._python_array_map is None:
            cls._init_python_array_map()

        value_type = type(value)
        if is_iterable(value) and value_type is not str:
            value_subtype = cls.get_subtype(value)
            if value_subtype in cls._python_array_map:
                return cls._python_array_map[value_subtype]

            # a little heuristics (order may be important)
            if all([
                value_subtype is None,
                len(value) == 2,
                isinstance(value[0], int),
                isinstance(value[1], dict),
            ]):
                return MapObject

            if all([
                value_subtype is None,
                len(value) == 2,
                isinstance(value[0], int),
                is_iterable(value[1]),
            ]):
                return ObjectArrayObject

            raise TypeError(
                'Type `array of {}` is invalid'.format(value_subtype)
            )

        if is_binary(value):
            return BinaryObject

        if value_type in cls._python_map:
            return cls._python_map[value_type]
        raise TypeError(
            'Type `{}` is invalid.'.format(value_type)
        )
    def map_python_type(cls, value):
        if cls._python_map is None or cls._python_array_map is None:
            cls._init_python_mapping()

        value_type = type(value)

        if value_type in cls._python_map:
            return cls._python_map[value_type]

        if is_iterable(value) and value_type not in (str, bytearray, bytes):
            value_subtype = cls.get_subtype(value)
            if value_subtype in cls._python_array_map:
                return cls._python_array_map[value_subtype]

            # a little heuristics (order is important)
            if all([
                    value_subtype is None,
                    len(value) == 2,
                    isinstance(value[0], int),
                    isinstance(value[1], dict),
            ]):
                return cls._map_obj_type

            if all([
                    value_subtype is None,
                    len(value) == 2,
                    isinstance(value[0], int),
                    is_iterable(value[1]),
            ]):
                return cls._collection_obj_type

            # no default for ObjectArrayObject, sorry

            raise TypeError(
                'Type `array of {}` is invalid'.format(value_subtype))

        if is_binary(value):
            return cls._binary_obj_type

        raise TypeError('Type `{}` is invalid.'.format(value_type))
def __cache_get_node_partitions(conn, caches, query_id):
    query_struct = Query(OP_CACHE_PARTITIONS, [
        ('cache_ids', cache_ids),
    ],
                         query_id=query_id)
    if not is_iterable(caches):
        caches = [caches]

    return query_perform(query_struct,
                         conn,
                         query_params={
                             'cache_ids': [{
                                 'cache_id': cache
                             } for cache in caches],
                         },
                         response_config=[
                             ('version_major', Long),
                             ('version_minor', Int),
                             ('partition_mapping', partition_mapping),
                         ],
                         post_process_fun=__post_process_partitions)
예제 #6
0
    def connect(self, *args):
        """
        Connect to the server. Connection parameters may be either one node
        (host and port), or list (or other iterable) of nodes.

        :param host: Ignite server host,
        :param port: Ignite server port,
        :param nodes: iterable of (host, port) tuples.
        """
        self.nodes = iter([])
        if len(args) == 0:
            host, port = IGNITE_DEFAULT_HOST, IGNITE_DEFAULT_PORT
        elif len(args) == 1 and is_iterable(args[0]):
            self.nodes = iter(args[0])
            host, port = next(self.nodes)
        elif (len(args) == 2 and isinstance(args[0], str)
              and isinstance(args[1], int)):
            host, port = args
        else:
            raise ConnectionError('Connection parameters are not valid.')

        self._connect(host, port)