示例#1
0
文件: call.py 项目: faasm/faasm
def _do_single_call(host, port, msg, quiet):
    url = "http://{}".format(host)
    if port != 80:
        url += ":{}/".format(port)

    headers = get_knative_headers()
    return do_post(url, msg, headers=headers, quiet=quiet, json=True)
示例#2
0
def _do_single_call(host, port, msg, quiet):
    url = "http://{}".format(host)
    if port != 80:
        url += ":{}/".format(port)

    # Can always use the faasm worker for getting status
    headers = _get_knative_headers("worker")
    return do_post(url, msg, headers=headers, quiet=quiet, json=True)
示例#3
0
def _do_single_call(user, func, host, port, msg, quiet, native=False):
    url = "http://{}".format(host)
    if port != 80:
        url += ":{}/".format(port)

    # If wasm, can always use the faasm worker for getting status
    if native:
        headers = _get_knative_headers(func)
    else:
        headers = _get_knative_headers("worker")

    return do_post(url, msg, headers=headers, quiet=quiet, json=True)
示例#4
0
def all(ctx):
    """
    Flush functions, state and shared files from all workers
    """
    host, port = get_invoke_host_port()
    msg = {
        "type": FAABRIC_MSG_TYPE_FLUSH,
    }

    url = "http://{}:{}".format(host, port)
    headers = get_knative_headers()
    return do_post(url, msg, headers=headers, quiet=False, json=True)
示例#5
0
文件: call.py 项目: sleipnir/faasm
def _async_invoke(url, msg, headers=None, poll=False, host=None, port=None):
    # Submit initial async call
    async_result = do_post(url, msg, headers=headers, quiet=True, json=True)

    try:
        call_id = int(async_result)
    except ValueError:
        raise RuntimeError(
            "Could not parse async response to int: {}".format(async_result))

    # Return the call ID if we're not polling
    if not poll:
        return call_id

    print("\n---- Polling {} ----".format(call_id))

    # Poll status until we get success/ failure
    result = None
    output = None
    count = 0
    while result != STATUS_SUCCESS:
        count += 1

        interval = float(POLL_INTERVAL_MS) / 1000
        sleep(interval)

        result, output = status_call_impl(msg["user"],
                                          msg["function"],
                                          call_id,
                                          host,
                                          port,
                                          quiet=True)
        print("\nPOLL {} - {}".format(count, result))

    print("\n---- Finished {} ----\n".format(call_id))
    print(output)

    if result == STATUS_SUCCESS:
        prefix = "SUCCESS:"
    else:
        prefix = "FAILED:"

    output = output.replace(prefix, "")

    return call_id
示例#6
0
文件: call.py 项目: sleipnir/faasm
def invoke_impl(
    user,
    func,
    input=None,
    py=False,
    asynch=False,
    knative=True,
    poll=False,
    cmdline=None,
    mpi_world_size=None,
    debug=False,
    sgx=False,
):
    host, port = get_invoke_host_port()

    # Polling always requires asynch
    if poll:
        asynch = True

    # Create URL and message
    url = "http://{}".format(host)
    if not port == "80":
        url += ":{}".format(port)

    if py:
        msg = {
            "user": PYTHON_USER,
            "function": PYTHON_FUNC,
            "async": asynch,
            "py_user": user,
            "py_func": func,
            "python": True,
        }
    else:
        msg = {
            "user": user,
            "function": func,
            "async": asynch,
        }

    if sgx:
        msg["sgx"] = sgx

    if input:
        msg["input_data"] = input

    if cmdline:
        msg["cmdline"] = cmdline

    if mpi_world_size:
        msg["mpi_world_size"] = mpi_world_size

    # Knative must pass custom headers
    if knative:
        headers = get_knative_headers()
    else:
        headers = {}

    if asynch:
        return _async_invoke(url,
                             msg,
                             headers=headers,
                             poll=poll,
                             host=host,
                             port=port)
    else:
        return do_post(url, msg, headers=headers, json=True, debug=debug)
示例#7
0
文件: call.py 项目: sleipnir/faasm
def _do_invoke(user, func, host, port, func_type, input=None):
    url = "http://{}:{}/{}/{}/{}".format(host, port, func_type, user, func)
    print("Invoking {}".format(url))
    do_post(url, input, json=True)
示例#8
0
def invoke_impl(
    user,
    func,
    host=None,
    port=None,
    input=None,
    py=False,
    asynch=False,
    knative=True,
    poll=False,
    cmdline=None,
    mpi_world_size=None,
    debug=False,
    poll_interval_ms=1000,
):
    # Provider-specific stuff
    if knative:
        host, port = get_invoke_host_port(host, port)

    # Defaults
    host = host if host else "127.0.0.1"
    port = port if port else 8080
    # Polling always requires asynch
    if poll:
        asynch = True
        # Create URL and message
    url = "http://{}".format(host)
    if not port == "80":
        url += ":{}".format(port)

    if py:
        msg = {
            "user": PYTHON_USER,
            "function": PYTHON_FUNC,
            "async": asynch,
            "py_user": user,
            "py_func": func,
            "python": True,
        }
    else:
        msg = {
            "user": user,
            "function": func,
            "async": asynch,
        }

    if input:
        msg["input_data"] = input

    if cmdline:
        msg["cmdline"] = cmdline

    if mpi_world_size:
        msg["mpi_world_size"] = mpi_world_size

    # Knative must pass custom headers
    if knative:
        headers = _get_knative_headers("worker")
    else:
        headers = {}
    if asynch:
        # Submit initial asynch call
        asynch_result = do_post(url,
                                msg,
                                headers=headers,
                                quiet=True,
                                json=True)
        try:
            call_id = int(asynch_result)
        except ValueError:
            raise RuntimeError(
                "Could not parse async response to int: {}".format(
                    asynch_result))

        if not poll:
            # Return the call ID if we're not polling
            return call_id
        else:
            if not knative:
                raise RuntimeError("Poll only supported for knative")

            print("\n---- Polling {} ----".format(call_id))

            # Poll status until we get success/ failure
            result = None
            output = None
            count = 0
            while result != STATUS_SUCCESS:
                count += 1

                interval = float(poll_interval_ms) / 1000
                sleep(interval)

                result, output = status_call_impl(user,
                                                  func,
                                                  call_id,
                                                  host,
                                                  port,
                                                  quiet=True)
                print("\nPOLL {} - {}".format(count, result))

            print("\n---- Finished {} ----\n".format(call_id))
            print(output)

            if result == STATUS_SUCCESS:
                prefix = "SUCCESS:"
                success = True
            else:
                prefix = "FAILED:"
                success = False

            output = output.replace(prefix, "")
            return success, output
    else:
        if knative:
            return do_post(url, msg, headers=headers, json=True, debug=debug)
        else:
            raise RuntimeError("Must specify knative")
示例#9
0
def invoke_impl(user, func,
                host=None,
                port=None,
                input=None,
                py=False,
                asynch=False,
                knative=True,
                native=False,
                ibm=False,
                poll=False,
                cmdline=None,
                mpi_world_size=None,
                debug=False,
                poll_interval_ms=1000):
    faasm_config = get_faasm_config()

    # Provider-specific stuff
    if ibm:
        host = faasm_config["IBM"]["k8s_subdomain"]
        port = 8080
    elif knative:
        host, port = get_invoke_host_port()

    # Defaults
    host = host if host else "127.0.0.1"
    port = port if port else 8080
    # Polling always requires asynch
    if poll:
        asynch = True
        # Create URL and message
    url = "http://{}".format(host)
    if not port == "80":
        url += ":{}".format(port)

    if py:
        msg = {
            "user": PYTHON_USER,
            "function": PYTHON_FUNC,
            "async": asynch,
            "py_user": user,
            "py_func": func,
            "python": True,
        }
    else:
        msg = {
            "user": user,
            "function": func,
            "async": asynch,
        }

    if input:
        msg["input_data"] = input

    if cmdline:
        msg["cmdline"] = cmdline

    if mpi_world_size:
        msg["mpi_world_size"] = mpi_world_size

    # IBM-specific message format
    if ibm:
        faasm_conf = get_faasm_config()
        msg.update({
            "IBM_API_KEY": faasm_conf["IBM"]["api_key"],
            "REDIS_QUEUE_HOST": faasm_conf["IBM"]["redis_host_public"],
            "REDIS_STATE_HOST": faasm_conf["IBM"]["redis_host_public"],
        })

        # Message needs to be nested
        msg = {
            "value": msg,
        }

    # IBM must call init first
    if ibm:
        do_post("http://{}:{}/init/".format(host, port), msg, json=True)

    # Knative must pass custom headers
    if knative and native:
        if py:
            headers = _get_knative_headers("python")
        else:
            headers = _get_knative_headers(func)
    elif knative:
        headers = _get_knative_headers("worker")
    else:
        headers = {}
    if asynch:
        # Submit initial asynch call
        asynch_result = do_post(url, msg, headers=headers, quiet=True, json=True)
        try:
            call_id = int(asynch_result)
        except ValueError:
            raise RuntimeError("Could not parse async response to int: {}".format(asynch_result))

        if not poll:
            # Return the call ID if we're not polling
            return call_id
        else:
            if not knative:
                raise RuntimeError("Poll only supported for knative")

            print("\n---- Polling {} ----".format(call_id))

            # Poll status until we get success/ failure
            result = None
            output = None
            count = 0
            while result != STATUS_SUCCESS:
                count += 1

                interval = float(poll_interval_ms) / 1000
                sleep(interval)

                result, output = status_call_impl(user, func, call_id, host, port, quiet=True, native=native)
                print("\nPOLL {} - {}".format(count, result))

            print("\n---- Finished {} ----\n".format(call_id))
            print(output)

            if result == STATUS_SUCCESS:
                prefix = "SUCCESS:"
                success = True
            else:
                prefix = "FAILED:"
                success = False

            output = output.replace(prefix, "")
            return success, output
    else:
        if ibm or knative:
            return do_post(url, msg, headers=headers, json=True, debug=debug)
        else:
            raise RuntimeError("Must specify knative or ibm")
示例#10
0
    if ibm:
        faasm_conf = get_faasm_config()
        msg.update({
            "IBM_API_KEY": faasm_conf["IBM"]["api_key"],
            "REDIS_QUEUE_HOST": faasm_conf["IBM"]["redis_host_public"],
            "REDIS_STATE_HOST": faasm_conf["IBM"]["redis_host_public"],
        })

        # Message needs to be nested
        msg = {
            "value": msg,
        }

    # IBM must call init first
    if ibm:
        do_post("http://{}:{}/init/".format(host, port), msg, json=True)

    # Knative must pass custom headers
    if knative and native:
        if py:
            headers = _get_knative_headers("python")
        else:
            headers = _get_knative_headers(func)
    elif knative:
        headers = _get_knative_headers("worker")
    else:
        headers = {}

    if async:
        # Submit initial async call
        async_result = do_post(url,