Пример #1
0
    def _build(self,
               startKey=None,
               endKey=None,
               startKeyInclusive=True,
               endKeyInclusive=True,
               maxReturned=200):
        if not startKey:
            startKey = ''
        if not endKey:
            endKey = '\xFF' * common.MAX_KEY_SIZE

        if len(startKey) > common.MAX_KEY_SIZE:
            raise common.KineticClientException(
                "Start key exceeds maximum size of {0} bytes.".format(
                    common.MAX_KEY_SIZE))
        if len(endKey) > common.MAX_KEY_SIZE:
            raise common.KineticClientException(
                "End key exceeds maximum size of {0} bytes.".format(
                    common.MAX_KEY_SIZE))

        m = self.m

        m.header.messageType = messages.Command.MEDIAOPTIMIZE

        kr = m.body.range
        kr.startKey = startKey
        kr.endKey = endKey
        kr.startKeyInclusive = startKeyInclusive
        kr.endKeyInclusive = endKeyInclusive
        kr.maxReturned = maxReturned

        return (m, None)
Пример #2
0
def _buildMessage(messageType, key, data=None, version='', new_version='',
                  force=False, tag=None, algorithm=None, synchronization=None):
    m = messages.Command()
    m.header.messageType = messageType
    if len(key) > common.MAX_KEY_SIZE: raise common.KineticClientException("Key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))
    m.body.keyValue.key = key
    if data:
        if len(data) > common.MAX_VALUE_SIZE: raise common.KineticClientException("Value exceeds maximum size of {0} bytes.".format(common.MAX_VALUE_SIZE))

    if tag and algorithm:
        m.body.keyValue.tag = tag
        m.body.keyValue.algorithm = algorithm
    elif messageType == messages.Command.PUT:
        m.body.keyValue.tag = 'l337'
        m.body.keyValue.algorithm = 1 # nacho: should be change to a value over 100
    if synchronization:
        m.body.keyValue.synchronization = synchronization
    if version:
        m.body.keyValue.dbVersion = version
    if new_version:
        m.body.keyValue.newVersion = new_version
    if force:
        m.body.keyValue.force = True

    return (m,data)
Пример #3
0
def _buildMessage(m,
                  messageType,
                  key,
                  data=None,
                  version='',
                  new_version='',
                  force=False,
                  tag=None,
                  algorithm=None,
                  synchronization=None):
    m.header.messageType = messageType
    if len(key) > common.MAX_KEY_SIZE:
        raise common.KineticClientException(
            "Key exceeds maximum size of {0} bytes.".format(
                common.MAX_KEY_SIZE))
    m.body.keyValue.key = key
    if data:
        if len(data) > common.MAX_VALUE_SIZE:
            raise common.KineticClientException(
                "Value exceeds maximum size of {0} bytes.".format(
                    common.MAX_VALUE_SIZE))

    if tag and algorithm:
        m.body.keyValue.tag = tag
        m.body.keyValue.algorithm = algorithm
    elif messageType == messages.Command.PUT:
        # check the data type first
        if data and (isinstance(data, str) or isinstance(data, bytes)
                     or isinstance(data, bytearray)):
            # default to sha1
            m.body.keyValue.tag = hashlib.sha1(data).digest()
            m.body.keyValue.algorithm = common.IntegrityAlgorithms.SHA1
        else:
            m.body.keyValue.tag = 'l337'

    if (messageType == messages.Command.PUT or messageType
            == messages.Command.DELETE) and synchronization == None:
        synchronization = common.Synchronization.WRITEBACK

    if synchronization:
        m.body.keyValue.synchronization = synchronization
    if version:
        m.body.keyValue.dbVersion = version
    if new_version:
        m.body.keyValue.newVersion = new_version
    if force:
        m.body.keyValue.force = True

    return (m, data)
Пример #4
0
    def _recv_delimited_v2(self):
        # receive the leading 9 bytes

        if self.wait_on_read:
            self.wait_on_read.wait()
            self.wait_on_read = None

        msg = self.fast_read(9)

        magic, proto_ln, value_ln = struct.unpack_from(">bii", buffer(msg))

        if magic!= 70:
            LOG.warn("Magic number = {0}".format(magic))
            raise common.KineticClientException("Invalid Magic Value!") # 70 = 'F'

        # read proto message
        raw_proto = self.fast_read(proto_ln)

        value = ''
        if value_ln > 0:
            if self.defer_read:
                # let user handle the read from socket
                value = common.DeferedValue(self.socket, value_ln)
                self.wait_on_read = value
            else:
                # normal code path, read value
                value = self.fast_read(value_ln)

        proto = messages.Message()
        proto.ParseFromString(str(raw_proto))

        return (proto, value)
Пример #5
0
    def _handshake(self):
        # Connection id handshake
        try:
            _,cmd,v = self.network_recv() # unsolicited status
        except socket.timeout:
            raise common.KineticClientException("Handshake timeout")

        # device locked only allowed to continue over SSL
        if (cmd.status.code == messages.Command.Status.DEVICE_LOCKED):
            if not self.use_ssl:
                raise KineticMessageException(cmd.status)
        elif (cmd.status.code != messages.Command.Status.SUCCESS):
            raise KineticMessageException(cmd.status)

        self.connection_id = cmd.header.connectionID

        self.config = cmd.body.getLog.configuration
        self.limits = cmd.body.getLog.limits

        if self.cluster_version:
            if self.cluster_version != cmd.header.clusterVersion:
                cmd.status.code = messages.Command.Status.VERSION_FAILURE
                cmd.status.statusMessage = \
                    'Cluster version missmatch detected during handshake'
                raise common.ClusterVersionFailureException(
                    cmd.status, cmd.header.clusterVersion)
        else:
            self.cluster_version = cmd.header.clusterVersion
Пример #6
0
    def build(startKey=None, endKey=None, startKeyInclusive=True, endKeyInclusive=True, maxReturned=200):
        if not startKey:
            startKey = ''
        if not endKey:
            endKey = '\xFF' * common.MAX_KEY_SIZE

        if len(startKey) > common.MAX_KEY_SIZE: raise common.KineticClientException("Start key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))
        if len(endKey) > common.MAX_KEY_SIZE: raise common.KineticClientException("End key exceeds maximum size of {0} bytes.".format(common.MAX_KEY_SIZE))

        m = messages.Command()

        m.header.messageType = messages.Command.BACKOP

        op = m.body.backgroundOperation
        op.backOpType = messages.Command.BackgroundOperation.MEDIASCAN

        kr = op.range
        kr.startKey = startKey
        kr.endKey = endKey
        kr.startKeyInclusive = startKeyInclusive
        kr.endKeyInclusive = endKeyInclusive
        kr.maxReturned = maxReturned

        return (m, None)