Esempio n. 1
0
def call_function(func_call_socket, pusher_cache, policy):
    # Parse the received protobuf for this function call.
    call = FunctionCall()
    call.ParseFromString(func_call_socket.recv())

    # If there is no response key set for this request, we generate a random
    # UUID.
    if not call.response_key:
        call.response_key = str(uuid.uuid4())

    # Filter the arguments for CloudburstReferences, and use the policy engine to
    # pick a node for this request.
    refs = list(
        filter(lambda arg: type(arg) == CloudburstReference,
               map(lambda arg: serializer.load(arg), call.arguments.values)))
    result = policy.pick_executor(refs)

    response = GenericResponse()
    if result is None:
        response.success = False
        response.error = NO_RESOURCES
        func_call_socket.send(response.SerializeToString())
        return

    # Forward the request on to the chosen executor node.
    ip, tid = result
    sckt = pusher_cache.get(utils.get_exec_address(ip, tid))
    sckt.send(call.SerializeToString())

    # Send a success response to the user with the response key.
    response.success = True
    response.response_id = call.response_key
    func_call_socket.send(response.SerializeToString())
Esempio n. 2
0
def call_function_from_queue(func_call_queue_socket, pusher_cache, policy):
    call = FunctionCall()
    call.ParseFromString(func_call_queue_socket.recv())

    # If there is no response key set for this request, we generate a random
    # UUID.
    if not call.response_key:
        call.response_key = str(uuid.uuid4())

    if call.source_hint == STORAGE:
        # It means the invocation is from storage,
        # so we parse the arguments in a different way
        # TODO remove loc from the original call
        loc_set = set(call.locations)
        result = policy.pick_executor_with_loc(call.name, loc_set)

        if result is None:
            logging.error('No executor available for STORAGE CALL')
            return

        ip, tid = result
        logging.info(
            'Pick executor %s:%d for STORAGE CALL %s with locations %s' %
            (ip, tid, call.name, loc_set))

        sckt = pusher_cache.get(utils.get_exec_address(ip, tid))
        sckt.send(call.SerializeToString())
Esempio n. 3
0
    def _create_function_call(self, fname, args, consistency):
        call = FunctionCall()
        call.name = fname
        call.request_id = 1
        call.response_key = self.response_key
        call.consistency = consistency

        for arg in args:
            val = call.arguments.values.add()
            serializer.dump(arg, val, False)

        return call