Exemplo n.º 1
0
def http_method(method_name):
    if request.method == 'GET':
        return render_template('xmlrpc-methods.html', methods = current_app.wl_server_methods)

    if method_name not in current_app.wl_server_methods:
        return "Method name not supported", 404

    server_instance = current_app.wl_server_instance

    raw_data = request.get_data()
    args = pickle.loads(raw_data)
    

    try:
        if method_name == 'test_me':
            result = args[0]
        else:
            method = getattr(server_instance, 'do_%s' % method_name)
            result = method(*args)
    except:
        exc_type, exc_instance, _ = sys.exc_info()
        remote_exc_type = _get_type_name(exc_type)
        log.error(__name__, 'Error on %s' % method_name)
        log.error_exc(__name__)
        return pickle.dumps({
            'is_error' : True,
            'error_type' : remote_exc_type,
            'error_args' : exc_instance.args,
        })
    else:
        return pickle.dumps({ 'result' : result })
Exemplo n.º 2
0
def http_method(method_name):
    if request.method == 'GET':
        return render_template('xmlrpc-methods.html', methods = current_app.wl_server_methods)

    if method_name not in current_app.wl_server_methods:
        return "Method name not supported", 404

    server_instance = current_app.wl_server_instance

    raw_data = request.get_data()
    args = pickle.loads(raw_data)
    

    try:
        if method_name == 'test_me':
            result = args[0]
        else:
            method = getattr(server_instance, 'do_%s' % method_name)
            result = method(*args)
    except:
        exc_type, exc_instance, _ = sys.exc_info()
        remote_exc_type = _get_type_name(exc_type)
        log.error(__name__, 'Error on %s' % method_name)
        log.error_exc(__name__)
        return pickle.dumps({
            'is_error' : True,
            'error_type' : remote_exc_type,
            'error_args' : exc_instance.args,
        })
    else:
        return pickle.dumps({ 'result' : result })
Exemplo n.º 3
0
def xmlrpc():
    if request.method == 'GET':
        return render_template('xmlrpc-methods.html', methods = current_app.wl_server_methods)

    raw_data = request.get_data()
    params, method_name = xmlrpclib.loads(raw_data)
    if method_name.startswith('Util.'):
        method_name = method_name[len('Util.'):]

    if method_name not in current_app.wl_server_methods:
        return xmlrpclib.dumps(xmlrpclib.Fault("Method not found", "Method not found"))

    try:
        if method_name == 'test_me':
            result = params[0]
        else:
            method = getattr(current_app.wl_server_instance, 'do_%s' % method_name)
            result = method(*params)
    except:
        exc_type, exc_instance, _ = sys.exc_info()
        remote_exc_type = _get_type_name(exc_type)
        fault = xmlrpclib.Fault(remote_exc_type, repr(exc_instance.args))
        log.error(__name__, 'Error on %s' % method_name)
        log.error_exc(__name__)
        return xmlrpclib.dumps(fault)

    return xmlrpclib.dumps( (result,))
Exemplo n.º 4
0
def xmlrpc():
    if request.method == 'GET':
        return render_template('xmlrpc-methods.html', methods = current_app.wl_server_methods)

    raw_data = request.get_data()
    params, method_name = xmlrpclib.loads(raw_data)
    if method_name.startswith('Util.'):
        method_name = method_name[len('Util.'):]

    if method_name not in current_app.wl_server_methods:
        return xmlrpclib.dumps(xmlrpclib.Fault("Method not found", "Method not found"))

    try:
        if method_name == 'test_me':
            result = params[0]
        else:
            method = getattr(current_app.wl_server_instance, 'do_%s' % method_name)
            result = method(*params)
    except:
        exc_type, exc_instance, _ = sys.exc_info()
        remote_exc_type = _get_type_name(exc_type)
        fault = xmlrpclib.Fault(remote_exc_type, repr(exc_instance.args))
        log.error(__name__, 'Error on %s' % method_name)
        log.error_exc(__name__)
        return xmlrpclib.dumps(fault, allow_none = True)

    return xmlrpclib.dumps( (result,), allow_none = True)
Exemplo n.º 5
0
    def _call(self, name, *args):
        # In the future (once we don't pass any weird arg, such as SessionId and so on), use JSON

        # First, serialize the data provided in the client side
        try:
            request_data = pickle.dumps(args)
        except:
            _, exc_instance, _ = sys.exc_info()
            raise InternalClientCommunicationError("Unknown client error contacting %s: %r" % (self.url, exc_instance))
        
        # Then, perform the request and deserialize the results
        t0 = time.time()
        try:
            kwargs = {}
            if name == 'test_me':
                kwargs['timeout'] = (10, 60)
            else:
                kwargs['timeout'] = (60, self.timeout or 600)
            if self.auth:
                kwargs['headers'] = {'X-WebLab-Auth': self.auth}
            content = requests.post(self.url + '/' + name, data = request_data, **kwargs).content
            result = pickle.loads(content)
        except:
            tf = time.time()
            _, exc_instance, _ = sys.exc_info()
            raise InternalServerCommunicationError("Unknown server error contacting %s with HTTP after %s seconds: %r" % (self.url, tf - t0, exc_instance))

        # result must be a dictionary which contains either 'result' 
        # with the resulting object or 'is_error' and some data about 
        # the exception

        if result.get('is_error'):
            error_type = result['error_type']
            error_args = result['error_args']
            if not isinstance(error_args, list) and not isinstance(error_args, tuple):
                error_args = [error_args]

            # If it's acceptable, raise the exception (e.g., don't raise a KeyboardInterrupt, a MemoryError, or a library error)
            if error_type.startswith(ACCEPTABLE_EXC_TYPES):
                exc_type = _load_type(error_type)
                try:
                    exc_instance = exc_type(*error_args)
                except TypeError:
                    # If we can't create it
                    log.error(__name__, 'Error on instantiating an exception %s(%r)' % (exc_type, error_args))
                    log.error_exc(__name__)
                    raise InternalCapturedServerCommunicationError(error_type, error_args)
                else:
                    raise exc_instance
            else:
                # Otherwise wrap it
                raise InternalCapturedServerCommunicationError(error_type, error_args)
        # No error? return the result
        return result['result']
Exemplo n.º 6
0
    def _call(self, name, *args):
        if name == 'test_me':
            return args[0]
        instance = GLOBAL_REGISTRY[self.coord_address_str]
        method = getattr(instance, 'do_%s' % name)
        try:
            return method(*args)
        except:
            exc_type, exc_instance, _ = sys.exc_info()
            remote_exc_type = _get_type_name(exc_type)
            if remote_exc_type.startswith(ACCEPTABLE_EXC_TYPES):
                raise

            log.error(__name__, 'Error on %s' % name)
            log.error_exc(__name__)

            remote_exc_args = exc_instance.args
            if not isinstance(remote_exc_args, list) and not isinstance(remote_exc_args, tuple):
                remote_exc_args = [remote_exc_args]
            
            raise InternalCapturedServerCommunicationError(remote_exc_type, remote_exc_args)
Exemplo n.º 7
0
    def _call(self, name, *args):
        if name == 'test_me':
            return args[0]
        instance = GLOBAL_REGISTRY[self.coord_address_str]
        method = getattr(instance, 'do_%s' % name)
        try:
            return method(*args)
        except:
            exc_type, exc_instance, _ = sys.exc_info()
            remote_exc_type = _get_type_name(exc_type)
            if remote_exc_type.startswith(ACCEPTABLE_EXC_TYPES):
                raise

            log.error(__name__, 'Error on %s' % name)
            log.error_exc(__name__)

            remote_exc_args = exc_instance.args
            if not isinstance(remote_exc_args, list) and not isinstance(
                    remote_exc_args, tuple):
                remote_exc_args = [remote_exc_args]

            raise InternalCapturedServerCommunicationError(
                remote_exc_type, remote_exc_args)
Exemplo n.º 8
0
    def _call(self, name, *args):
        # In the future (once we don't pass any weird arg, such as SessionId and so on), use JSON

        # First, serialize the data provided in the client side
        try:
            request_data = pickle.dumps(args)
        except:
            _, exc_instance, _ = sys.exc_info()
            raise InternalClientCommunicationError(
                "Unknown client error contacting %s: %r" %
                (self.url, exc_instance))

        # Then, perform the request and deserialize the results
        t0 = time.time()
        try:
            kwargs = {}
            if name == 'test_me':
                kwargs['timeout'] = (10, 60)
            else:
                kwargs['timeout'] = (60, self.timeout or 600)
            if self.auth:
                kwargs['headers'] = {'X-WebLab-Auth': self.auth}
            content = requests.post(self.url + '/' + name,
                                    data=request_data,
                                    **kwargs).content
            result = pickle.loads(content)
        except:
            tf = time.time()
            _, exc_instance, _ = sys.exc_info()
            raise InternalServerCommunicationError(
                "Unknown server error contacting %s with HTTP after %s seconds: %r"
                % (self.url, tf - t0, exc_instance))

        # result must be a dictionary which contains either 'result'
        # with the resulting object or 'is_error' and some data about
        # the exception

        if result.get('is_error'):
            error_type = result['error_type']
            error_args = result['error_args']
            if not isinstance(error_args, list) and not isinstance(
                    error_args, tuple):
                error_args = [error_args]

            # If it's acceptable, raise the exception (e.g., don't raise a KeyboardInterrupt, a MemoryError, or a library error)
            if error_type.startswith(ACCEPTABLE_EXC_TYPES):
                exc_type = _load_type(error_type)
                try:
                    exc_instance = exc_type(*error_args)
                except TypeError:
                    # If we can't create it
                    log.error(
                        __name__,
                        'Error on instantiating an exception %s(%r)' %
                        (exc_type, error_args))
                    log.error_exc(__name__)
                    raise InternalCapturedServerCommunicationError(
                        error_type, error_args)
                else:
                    raise exc_instance
            else:
                # Otherwise wrap it
                raise InternalCapturedServerCommunicationError(
                    error_type, error_args)
        # No error? return the result
        return result['result']