huskar_api/api/service_instance.py
def post(self, application_name, cluster_name, key):
        """Updates the weight of specified service instance.

        :param application_name: The name of application.
        :param cluster_name: The name of cluster.
        :param key: The key of service instance.
        :form weight: The target weight of instance. It should be a positive
                      integer.
        :form ephemeral: Whether the modification be ephemeral or persistent.
                         Must be ephemeral (``1``) for now.
        :form ttl: When ephemeral is ``1``, will use this value as ttl.
                   default: 5 * 60 s.
        :<header Authorization: Huskar Token (See :ref:`token`)
        :status 400: The request body is invalid.
        :status 404: The instance is not found.
        :status 409: There is another request has modified the instance.
        :status 200: The weight is updated successfully.
        """
        check_application_auth(application_name, Authority.WRITE)
        check_cluster_name(cluster_name, application_name)
        validate_fields(instance_schema, {
            'application': application_name,
            'cluster': cluster_name,
            'key': key,
        })

        weight = request.form.get('weight', type=int)
        if not weight or weight < 0:
            abort(400, 'weight must be a positive integer')
        weight = unicode(weight)
        ephemeral = request.form.get('ephemeral', type=int)
        if ephemeral != 1:
            abort(400, 'ephemeral must be "1" for now')

        im = InstanceManagement(
            huskar_client, application_name, SERVICE_SUBDOMAIN)
        instance, _ = im.get_instance(cluster_name, key, resolve=False)

        if instance.stat is None:
            abort(404, '%s %s/%s/%s does not exist' % (
                SERVICE_SUBDOMAIN, application_name, cluster_name, key,
            ))

        try:
            old_data = instance.data
            new_data = json.loads(instance.data)
            meta = new_data.setdefault('meta', {})
            meta['weight'] = weight
            new_data = json.dumps(new_data)
            instance.data = new_data
        except (ValueError, TypeError):
            capture_exception()  # unexpected exception should be captured
            abort(500)

        try:
            instance.save()
        except OutOfSyncError:
            abort(409, '%s %s/%s/%s has been modified by another request' % (
                SERVICE_SUBDOMAIN, application_name, cluster_name, key,
            ))

        audit_log.emit(
            audit_log.types.UPDATE_SERVICE,
            application_name=application_name,
            cluster_name=cluster_name,
            key=key,
            old_data=old_data,
            new_data=new_data)

        return api_response()
Updates the weight of specified service instance.

        :param application_name: The name of application.
        :param cluster_name: The name of cluster.
        :param key: The key of service instance.
        :form weight: The target weight of instance. It should be a positive
                      integer.
        :form ephemeral: Whether the modification be ephemeral or persistent.
                         Must be ephemeral (``1``) for now.
        :form ttl: When ephemeral is ``1``, will use this value as ttl.
                   default: 5 * 60 s.
        :<header Authorization: Huskar Token (See :ref:`token`)
        :status 400: The request body is invalid.
        :status 404: The instance is not found.
        :status 409: There is another request has modified the instance.
        :status 200: The weight is updated successfully.
        
Updates the weight of specified service instance.
Updates the weight of specified service instance .
def post(self, application_name, cluster_name, key):
        check_application_auth(application_name, Authority.WRITE)
        check_cluster_name(cluster_name, application_name)
        validate_fields(instance_schema, {
            'application': application_name,
            'cluster': cluster_name,
            'key': key,
        })
        weight = request.form.get('weight', type=int)
        if not weight or weight < 0:
            abort(400, 'weight must be a positive integer')
        weight = unicode(weight)
        ephemeral = request.form.get('ephemeral', type=int)
        if ephemeral != 1:
            abort(400, 'ephemeral must be "1" for now')
        im = InstanceManagement(
            huskar_client, application_name, SERVICE_SUBDOMAIN)
        instance, _ = im.get_instance(cluster_name, key, resolve=False)
        if instance.stat is None:
            abort(404, '%s %s/%s/%s does not exist' % (
                SERVICE_SUBDOMAIN, application_name, cluster_name, key,
            ))
        try:
            old_data = instance.data
            new_data = json.loads(instance.data)
            meta = new_data.setdefault('meta', {})
            meta['weight'] = weight
            new_data = json.dumps(new_data)
            instance.data = new_data
        except (ValueError, TypeError):
            capture_exception()  
            abort(500)
        try:
            instance.save()
        except OutOfSyncError:
            abort(409, '%s %s/%s/%s has been modified by another request' % (
                SERVICE_SUBDOMAIN, application_name, cluster_name, key,
            ))
        audit_log.emit(
            audit_log.types.UPDATE_SERVICE,
            application_name=application_name,
            cluster_name=cluster_name,
            key=key,
            old_data=old_data,
            new_data=new_data)
        return api_response()
def post ( self , application_name , cluster_name , key ) : check_application_auth ( application_name , Authority . WRITE ) check_cluster_name ( cluster_name , application_name ) validate_fields ( instance_schema , { 'application' : application_name , 'cluster' : cluster_name , 'key' : key , } ) weight = request . form . get ( 'weight' , type = int ) if not weight or weight < 0 : abort ( 400 , 'weight must be a positive integer' ) weight = unicode ( weight ) ephemeral = request . form . get ( 'ephemeral' , type = int ) if ephemeral != 1 : abort ( 400 , 'ephemeral must be "1" for now' ) im = InstanceManagement ( huskar_client , application_name , SERVICE_SUBDOMAIN ) instance , _ = im . get_instance ( cluster_name , key , resolve = False ) if instance . stat is None : abort ( 404 , '%s %s/%s/%s does not exist' % ( SERVICE_SUBDOMAIN , application_name , cluster_name , key , ) ) try : old_data = instance . data new_data = json . loads ( instance . data ) meta = new_data . setdefault ( 'meta' , { } ) meta [ 'weight' ] = weight new_data = json . dumps ( new_data ) instance . data = new_data except ( ValueError , TypeError ) : capture_exception ( ) abort ( 500 ) try : instance . save ( ) except OutOfSyncError : abort ( 409 , '%s %s/%s/%s has been modified by another request' % ( SERVICE_SUBDOMAIN , application_name , cluster_name , key , ) ) audit_log . emit ( audit_log . types . UPDATE_SERVICE , application_name = application_name , cluster_name = cluster_name , key = key , old_data = old_data , new_data = new_data ) return api_response ( )
Updates the weight of specified service instance.
Updates the weight of specified service instance .
"""Updates the weight of specified service instance.

        :param application_name: The name of application.
        :param cluster_name: The name of cluster.
        :param key: The key of service instance.
        :form weight: The target weight of instance. It should be a positive
                      integer.
        :form ephemeral: Whether the modification be ephemeral or persistent.
                         Must be ephemeral (``1``) for now.
        :form ttl: When ephemeral is ``1``, will use this value as ttl.
                   default: 5 * 60 s.
        :<header Authorization: Huskar Token (See :ref:`token`)
        :status 400: The request body is invalid.
        :status 404: The instance is not found.
        :status 409: There is another request has modified the instance.
        :status 200: The weight is updated successfully.
        """ # unexpected exception should be captured
self
application_name
The name of application.
The name of application .
cluster_name
The name of cluster.
The name of cluster .
key
The key of service instance.
The key of service instance .
form
The target weight of instance. It should be a positive
integer.
The target weight of instance . It should be a positive integer .
form
Whether the modification be ephemeral or persistent.
Must be ephemeral (``1``) for now.
Whether the modification be ephemeral or persistent . Must be ephemeral ( ` ` 1 ` ` ) for now .
form
When ephemeral is ``1``, will use this value as ttl.
When ephemeral is ` ` 1 ` ` will use this value as ttl .
<header
Huskar Token (See :ref:`token`)
Huskar Token ( See : ref : ` token ` )
status
The request body is invalid.
The request body is invalid .
status
The instance is not found.
The instance is not found .
status
There is another request has modified the instance.
There is another request has modified the instance .
status
The weight is updated successfully.
The weight is updated successfully .