コード例 #1
0
ファイル: shards.py プロジェクト: AndreMouche/marconi
    def on_patch(self, request, response, project_id, shard):
        """Allows one to update a shard's weight, uri, and/or options.

        This method expects the user to submit a JSON object
        containing atleast one of: 'uri', 'weight', 'options'. If
        none are found, the request is flagged as bad. There is also
        strict format checking through the use of
        jsonschema. Appropriate errors are returned in each case for
        badly formatted input.

        :returns: HTTP | 200,400
        """
        LOG.debug(u'PATCH shard - name: %s', shard)
        data = utils.load(request)

        EXPECT = ('weight', 'uri', 'options')
        if not any([(field in data) for field in EXPECT]):
            LOG.debug(u'PATCH shard, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                'One of `uri`, `weight`, or `options` needs '
                'to be specified'
            )

        for field in EXPECT:
            utils.validate(self._validators[field], data)

        fields = common_utils.fields(data, EXPECT,
                                     pred=lambda v: v is not None)

        try:
            self._ctrl.update(shard, **fields)
        except errors.ShardDoesNotExist as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()
コード例 #2
0
ファイル: pools.py プロジェクト: peoplemerge/marconi
 def update(self, name, **kwargs):
     names = ("uri", "weight", "options")
     fields = common_utils.fields(kwargs, names, pred=lambda x: x is not None, key_transform=lambda x: x[0])
     assert fields, "`weight`, `uri`, or `options` not found in kwargs"
     res = self._col.update({"n": name}, {"$set": fields}, upsert=False)
     if not res["updatedExisting"]:
         raise errors.PoolDoesNotExist(name)
コード例 #3
0
ファイル: shards.py プロジェクト: anhsirksai/marconi-redis
 def update(self, name, **kwargs):
     names = ('uri', 'weight', 'options')
     fields = common_utils.fields(kwargs, names,
                                  pred=lambda x: x is not None,
                                  key_transform=lambda x: x[0])
     assert fields, '`weight`, `uri`, or `options` not found in kwargs'
     fields['o'] = msgpack.dumps(fields['o'])
     self._db.hmset(_key(name), fields)
コード例 #4
0
ファイル: shards.py プロジェクト: anhsirksai/marconi-redis
 def update(self, name, **kwargs):
     names = ('uri', 'weight', 'options')
     fields = common_utils.fields(kwargs,
                                  names,
                                  pred=lambda x: x is not None,
                                  key_transform=lambda x: x[0])
     assert fields, '`weight`, `uri`, or `options` not found in kwargs'
     fields['o'] = msgpack.dumps(fields['o'])
     self._db.hmset(_key(name), fields)
コード例 #5
0
 def update(self, name, **kwargs):
     names = ('uri', 'weight', 'options')
     fields = common_utils.fields(kwargs,
                                  names,
                                  pred=lambda x: x is not None,
                                  key_transform=lambda x: x[0])
     assert fields, '`weight`, `uri`, or `options` not found in kwargs'
     res = self._col.update({'n': name}, {'$set': fields}, upsert=False)
     if not res['updatedExisting']:
         raise errors.ShardDoesNotExist(name)
コード例 #6
0
ファイル: shards.py プロジェクト: AndreMouche/marconi
 def update(self, name, **kwargs):
     names = ('uri', 'weight', 'options')
     fields = common_utils.fields(kwargs, names,
                                  pred=lambda x: x is not None,
                                  key_transform=lambda x: x[0])
     assert fields, '`weight`, `uri`, or `options` not found in kwargs'
     res = self._col.update({'n': name},
                            {'$set': fields},
                            upsert=False)
     if not res['updatedExisting']:
         raise errors.ShardDoesNotExist(name)
コード例 #7
0
ファイル: pools.py プロジェクト: peoplemerge/marconi
    def update(self, name, **kwargs):
        # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid
        # overwriting the existing options field with None, since that
        # one can be null.
        names = ("uri", "weight", "options")
        fields = common_utils.fields(kwargs, names, pred=lambda x: x is not None)

        assert fields, "`weight`, `uri`, or `options` not found in kwargs"

        if "options" in fields:
            fields["options"] = utils.json_encode(fields["options"])

        stmt = sa.sql.update(tables.Pools).where(tables.Pools.c.name == name).values(**fields)

        res = self._conn.execute(stmt)
        if res.rowcount == 0:
            raise errors.PoolDoesNotExist(name)
コード例 #8
0
ファイル: shards.py プロジェクト: TheSriram/marconi-1
    def update(self, name, **kwargs):
        # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid
        # overwriting the existing options field with None, since that
        # one can be null.
        names = ('uri', 'weight', 'options')
        fields = common_utils.fields(kwargs, names,
                                     pred=lambda x: x is not None)

        assert fields, '`weight`, `uri`, or `options` not found in kwargs'

        if 'options' in fields:
            fields['options'] = json.dumps(fields['options'])

        stmt = sa.sql.update(tables.Shards).where(
            tables.Shards.c.name == name).values(**fields)

        res = self._conn.execute(stmt)
        if res.rowcount == 0:
            raise errors.ShardDoesNotExist(name)
コード例 #9
0
    def update(self, name, **kwargs):
        # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid
        # overwriting the existing options field with None, since that
        # one can be null.
        names = ('uri', 'weight', 'options')
        fields = common_utils.fields(kwargs,
                                     names,
                                     pred=lambda x: x is not None)

        assert fields, '`weight`, `uri`, or `options` not found in kwargs'

        if 'options' in fields:
            fields['options'] = json.dumps(fields['options'])

        stmt = sa.sql.update(
            tables.Shards).where(tables.Shards.c.name == name).values(**fields)

        res = self._conn.execute(stmt)
        if res.rowcount == 0:
            raise errors.ShardDoesNotExist(name)
コード例 #10
0
ファイル: pools.py プロジェクト: PrashanthRaghu/marconi-redis
    def on_patch(self, request, response, project_id, pool):
        """Allows one to update a pool's weight, uri, and/or options.

        This method expects the user to submit a JSON object
        containing at least one of: 'uri', 'weight', 'options'. If
        none are found, the request is flagged as bad. There is also
        strict format checking through the use of
        jsonschema. Appropriate errors are returned in each case for
        badly formatted input.

        :returns: HTTP | 200,400
        """
        LOG.debug(u'PATCH pool - name: %s', pool)
        data = utils.load(request)

        EXPECT = ('weight', 'uri', 'options')
        if not any([(field in data) for field in EXPECT]):
            LOG.debug(u'PATCH pool, bad params')
            raise wsgi_errors.HTTPBadRequestBody(
                'One of `uri`, `weight`, or `options` needs '
                'to be specified')

        for field in EXPECT:
            utils.validate(self._validators[field], data)

        if 'uri' in data and not storage_utils.can_connect(data['uri']):
            raise wsgi_errors.HTTPBadRequestBody('cannot connect to %s' %
                                                 data['uri'])
        fields = common_utils.fields(data,
                                     EXPECT,
                                     pred=lambda v: v is not None)

        try:
            self._ctrl.update(pool, **fields)
        except errors.PoolDoesNotExist as ex:
            LOG.exception(ex)
            raise falcon.HTTPNotFound()