Ejemplo n.º 1
0
 def GET(self,
         request,
         client_ns=None,
         action=None,
         rid=None,
         object_name=None):
     if client_ns is None:
         # GET to / returns a list of clients
         return Response(
             'Not Implemented GET ' +
             request.reconstructed_url)  # TODO: Return list of clients
     elif action == None:
         # Get to /$clientId returns the info object for that remote node
         return Response(
             simplejson.dumps(
                 self.events_node.client_map[client_ns].registration_obj))
     elif action == 'jsonstream':
         # Get to /$clientId/jsonstream returns a stream of JSON objects.
         return self.events_node.client_map[client_ns].get_json_stream()
     elif action == 'listeners':
         if rid is None:
             # Get to /$clientId/listeners retuns a list of listeners
             return Response(
                 'Not Implemented GET ' +
                 request.reconstructed_url)  #TODO: Return listeners info
         else:
             # Get to /$clientId/listeners/$namespace returns the info for a listener
             return Response(
                 'Not Implemented GET ' +
                 request.reconstructed_url)  #TODO: Return listener info
     elif action == 'ror':
         return Response(
             simplejson.dumps(
                 getattr(self.events_node, rid)(client_ns, object_name)))
Ejemplo n.º 2
0
    def POST(self,
             request,
             client_ns=None,
             action=None,
             ror_action=None,
             ror_name=None):
        """Client API POST handler"""
        body = str(request.body)
        if len(body) is 0:
            obj = None
        else:
            obj = simplejson.loads(body)
        if client_ns is None:
            # POST to / is a remote node registration call
            namespace = obj.pop('client-namespace')
            client_ns = self.events_node.register(namespace, obj)
            return Response303(
                with_slash(request.reconstructed_url) + client_ns)

        elif action == 'listeners':
            # POST to /$clientId/listeners adds a remote listener
            namespace = obj.pop('namespace')
            listener = self.events_node.client_map[client_ns].listener
            self.events_node.add_listener(namespace, listener)
            return Response303(
                with_slash(request.reconstructed_url) + namespace)
        elif action == 'ror':
            if ror_action == 'callFunction' or ror_action == 'createInstance':
                if obj:
                    if obj.has_key('args'): args = obj['args']
                    else: args = []
                    if obj.has_key('kwargs'): kwargs = obj['kwargs']
                    else: kwargs = {}
                else:
                    args = []
                    kwargs = {}
                resp = getattr(self.events_node,
                               ror_action)(client_ns, ror_name, args, kwargs)
                return Response(simplejson.dumps(resp))
            if ror_action == 'setItem' or ror_action == 'setAttribute':
                args = {'attr': obj['attribute'], 'value': obj['value']}
                if obj.has_key('reference'):
                    args['reference'] = obj['reference']
                resp = getattr(self.events_node, ror_action)(client_ns,
                                                             ror_name, **args)
                return Response(simplejson.dumps(resp))
Ejemplo n.º 3
0
    def POST(self, request, collection):
        if collection == 'testrun':
            obj = json.loads(str(request.body))
            if 'tests' not in obj:
                return Response('invalid, has not tests')
            obj['type'] = 'test-run'
            info = self.db.create(obj)

            f_info = self.create_failure_document(self.db.get(info['id']),
                                                  stale=False)
        return JSONResponse({'testrun': info, 'failure_info': f_info})
Ejemplo n.º 4
0
 def GET(self, request, collection=None):
     return Response(str(collection))
Ejemplo n.º 5
0
 def PUT(self, request, ns):
     self.events_node._fire_event(ns, simplejson.loads(str(request.body)))
     return Response('')