示例#1
0
    def get(self, application_name, cluster_name):
        """Gets the outgoing route of specific cluster.

        Example of response::

           {
             "status": "SUCCESS",
             "message": "",
             "data": {
               "route": [
                 {"application_name": "base.foo", "intent": "direct",
                  "cluster_name": "alta1-channel-stable-1"},
                 {"application_name": "base.bar", "intent": "direct",
                  "cluster_name": "alta1-channel-stable-1"},
                 {"application_name": "base.baz", "intent": "direct",
                  "cluster_name": null},
               ]
             }
           }

        :param application_name: The name of source application.
        :param cluster_name: The name of source cluster.
        :<header Authorization: Huskar Token (See :ref:`token`)
        :status 200: The result is in the response.
        """
        check_application(application_name)
        check_cluster_name(cluster_name, application_name)
        facade = RouteManagement(huskar_client, application_name, cluster_name)
        route = sorted({
            'application_name': route[0],
            'intent': route[1],
            'cluster_name': route[2],
        } for route in facade.list_route())
        return api_response({'route': route})
示例#2
0
def test_rollback_route_change(db, client, faker, test_application_name,
                               admin_token, action_type, cluster_name,
                               dest_application_name, destination_cluster_name,
                               zk):
    action = action_creator.make_action(
        action_type,
        application_name=test_application_name,
        cluster_name=cluster_name,
        intent='direct',
        dest_application_name=dest_application_name,
        dest_cluster_name=destination_cluster_name)
    audit_log = AuditLog.create(0, faker.ipv4(), action)
    db.close()

    rm = RouteManagement(huskar_client, test_application_name, cluster_name)
    prev_destination_cluster = faker.uuid4()[:8]
    for cluster in [destination_cluster_name, prev_destination_cluster]:
        path = '/huskar/service/%s/%s/fo' % (dest_application_name, cluster)
        zk.ensure_path(path)
    rm.set_route(dest_application_name, prev_destination_cluster)

    r = client.put('/api/audit-rollback/%s/%s' %
                   (test_application_name, audit_log.id),
                   headers={'Authorization': admin_token})
    assert_response_ok(r)
    if action_type == action_types.DELETE_ROUTE:
        result = [(dest_application_name, 'direct', destination_cluster_name)]
    else:
        result = []
    assert list(rm.list_route()) == result
示例#3
0
    def delete(self, application_name):
        """Discards a default route policy of specific application.

        :param application_name: The name of specific application.
        :form ezone: Optional. The ezone of default route. Default: ``overall``
        :form intent: Optional. The intent of default route. Default:
                      ``direct``
        :<header Authorization: Huskar Token (See :ref:`token`)
        :status 200: Operation success.
        """
        check_application_auth(application_name, Authority.WRITE)
        ezone = request.form.get('ezone') or OVERALL
        intent = request.form.get('intent') or ROUTE_DEFAULT_INTENT
        facade = RouteManagement(huskar_client, application_name, None)
        try:
            default_route = facade.discard_default_route(ezone, intent)
        except ValueError as e:
            # TODO: Use a better validator instead
            return api_response(status='InvalidArgument',
                                message=first(e.args, '')), 400
        audit_log.emit(audit_log.types.DELETE_DEFAULT_ROUTE,
                       application_name=application_name,
                       ezone=ezone,
                       intent=intent)
        return api_response({
            'default_route':
            default_route,
            'global_default_route':
            settings.ROUTE_DEFAULT_POLICY
        })
示例#4
0
 def _delete(self, application_name, cluster_name, dest_application_name):
     intent = self._get_intent()
     facade = RouteManagement(huskar_client, application_name, cluster_name)
     dest_cluster_name = facade.discard_route(dest_application_name, intent)
     audit_log.emit(audit_log.types.DELETE_ROUTE,
                    application_name=application_name,
                    cluster_name=cluster_name,
                    intent=intent,
                    dest_application_name=dest_application_name,
                    dest_cluster_name=dest_cluster_name)
示例#5
0
 def declare_upstream_from_request(self, request_data):
     if not g.auth.is_application or not g.cluster_name:
         return
     if not switch.is_switched_on(SWITCH_ENABLE_DECLARE_UPSTREAM):
         return
     route_management = RouteManagement(huskar_client, g.auth.username,
                                        g.cluster_name)
     application_names = frozenset(request_data.get(SERVICE_SUBDOMAIN, []))
     try:
         route_management.declare_upstream(application_names)
     except Exception:
         capture_exception(level=logging.WARNING)
示例#6
0
 def _put(self, application_name, cluster_name, dest_application_name):
     dest_cluster_name = request.form['cluster_name'].strip()
     check_cluster_name(dest_cluster_name, dest_application_name)
     intent = self._get_intent()
     facade = RouteManagement(huskar_client, application_name, cluster_name)
     try:
         facade.set_route(dest_application_name, dest_cluster_name, intent)
     except EmptyClusterError as e:
         abort(400, unicode(e))
     audit_log.emit(audit_log.types.UPDATE_ROUTE,
                    application_name=application_name,
                    cluster_name=cluster_name,
                    intent=intent,
                    dest_application_name=dest_application_name,
                    dest_cluster_name=dest_cluster_name)
示例#7
0
    def get(self, application_name):
        """Gets the default route policy of specific application.

        Example of response::

           {
             "status": "SUCCESS",
             "message": "",
             "data": {
               "default_route": {
                 "overall": {
                   "direct": "channel-stable-2"
                 },
                 "altb1": {
                   "direct": "channel-stable-1"
                 }
               },
               "global_default_route": {
                 "direct": "channel-stable-2"
               }
             }
           }

        :param application_name: The name of specific application.
        :<header Authorization: Huskar Token (See :ref:`token`)
        :status 200: The result is in the response.
        """
        check_application(application_name)
        facade = RouteManagement(huskar_client, application_name, None)
        default_route = facade.get_default_route()
        return api_response({
            'default_route':
            default_route,
            'global_default_route':
            settings.ROUTE_DEFAULT_POLICY
        })
示例#8
0
def rollback_route_action(action_type, action_data):
    application_name = action_data['application_name']
    cluster_name = action_data['cluster_name']
    intent = action_data['intent']
    dest_application_name = action_data['dest_application_name']
    dest_cluster_name = action_data.get('dest_cluster_name')
    rm = RouteManagement(huskar_client, application_name, cluster_name)
    if action_type == action_types.DELETE_ROUTE:
        rm.set_route(dest_application_name, dest_cluster_name)
        new_action_type = action_types.UPDATE_ROUTE
    else:
        rm.discard_route(dest_application_name)
        new_action_type = action_types.DELETE_ROUTE
    return new_action_type, {
        'application_name': application_name,
        'cluster_name': cluster_name,
        'intent': intent,
        'dest_application_name': dest_application_name,
        'dest_cluster_name': dest_cluster_name
    }
示例#9
0
def route_management(test_application_name):
    return RouteManagement(
        huskar_client, test_application_name, 'alta1-stable')
示例#10
0
def route_management(test_application):
    return RouteManagement(huskar_client, test_application.application_name,
                           None)
示例#11
0
def route_management(faker):
    return RouteManagement(
        huskar_client=huskar_client,
        application_name=faker.uuid4()[:8],
        cluster_name='altb1-channel-stable-1',
    )