Verified Commit be8d7d1d authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

scord: Rewrite `ADM_remove_adhoc_storage` RPC

parent 47bef9b1
Loading
Loading
Loading
Loading
+23 −27
Original line number Diff line number Diff line
@@ -535,42 +535,38 @@ update_adhoc_storage(const server& srv, const adhoc_storage::ctx& new_ctx,
admire::error_code
remove_adhoc_storage(const server& srv, const adhoc_storage& adhoc_storage) {

    (void) srv;
    (void) adhoc_storage;

    return admire::error_code::snafu;

#if 0
    scord::network::rpc_client rpc_client{srv.protocol(), rpc_registration_cb};
    scord::network::client rpc_client{srv.protocol()};

    const auto rpc_id = ::api::remote_procedure::new_id();
    auto endp = rpc_client.lookup(srv.address());

    if(const auto& lookup_rv = rpc_client.lookup(srv.address());
       lookup_rv.has_value()) {
        const auto& endp = lookup_rv.value();

        LOGGER_INFO("rpc id: {} name: {} from: {} => "
                "body: {{adhoc_storage_id: {}}}",
                    "body: {{adhoc_id: {}}}",
                    rpc_id, std::quoted("ADM_"s + __FUNCTION__),
                    std::quoted(rpc_client.self_address()), adhoc_storage.id());

    ADM_remove_adhoc_storage_in_t in{adhoc_storage.id()};
    ADM_remove_adhoc_storage_out_t out;
        if(const auto& call_rv =
                   endp.call("ADM_"s + __FUNCTION__, adhoc_storage.id());
           call_rv.has_value()) {

    const auto rpc = endp.call("ADM_remove_adhoc_storage", &in, &out);
            const scord::network::generic_response resp{call_rv.value()};

    if(const auto rv = admire::error_code{out.retval}; !rv) {
        LOGGER_ERROR("rpc id: {} name: {} from: {} <= "
            LOGGER_EVAL(resp.error_code(), INFO, ERROR,
                        "rpc id: {} name: {} from: {} <= "
                        "body: {{retval: {}}} [op_id: {}]",
                        rpc_id, std::quoted("ADM_"s + __FUNCTION__),
                     std::quoted(rpc.origin()), rv, out.op_id);
        return rv;
                        std::quoted(endp.address()), resp.error_code(),
                        resp.op_id());

            return resp.error_code();
        }
    }

    LOGGER_INFO("rpc id: {} name: {} from: {} <= "
                "body: {{retval: {}}} [op_id: {}]",
                rpc_id, std::quoted("ADM_"s + __FUNCTION__),
                std::quoted(rpc.origin()), admire::error_code::success,
                out.op_id);
    return admire::error_code::success;
#endif
    LOGGER_ERROR("rpc call failed");
    return admire::error_code::other;
}

tl::expected<admire::pfs_storage, admire::error_code>
+27 −53
Original line number Diff line number Diff line
@@ -197,9 +197,34 @@ update_adhoc_storage(const request& req, std::uint64_t adhoc_id,

    req.respond(resp);
}

void
remove_adhoc_storage(const request& req, std::uint64_t adhoc_id) {

    using scord::network::get_address;

    const auto rpc_name = "ADM_"s + __FUNCTION__;
    const auto rpc_id = remote_procedure::new_id();

    LOGGER_INFO("rpc id: {} name: {} from: {} => "
                "body: {{adhoc_id: {}}}",
                rpc_id, std::quoted(rpc_name), std::quoted(get_address(req)),
                adhoc_id);

    auto& adhoc_manager = scord::adhoc_storage_manager::instance();
    admire::error_code ec = adhoc_manager.remove(adhoc_id);

    if(!ec) {
        LOGGER_ERROR("rpc id: {} error_msg: \"Error removing job: {}\"", rpc_id,
                     adhoc_id);
    }

    const auto resp = generic_response{rpc_id, ec};

    LOGGER_INFO("rpc id: {} name: {} to: {} <= "
                "body: {{retval: {}}}",
                rpc_id, std::quoted(__FUNCTION__),
                std::quoted(get_address(req)), ec);
                rpc_id, std::quoted(rpc_name), std::quoted(get_address(req)),
                ec);

    req.respond(resp);
}
@@ -323,57 +348,6 @@ ADM_remove_job(hg_handle_t h) {

DEFINE_MARGO_RPC_HANDLER(ADM_remove_job);


static void
ADM_remove_adhoc_storage(hg_handle_t h) {

    using scord::network::utils::get_address;

    [[maybe_unused]] hg_return_t ret;

    ADM_remove_adhoc_storage_in_t in;
    ADM_remove_adhoc_storage_out_t out;

    [[maybe_unused]] margo_instance_id mid = margo_hg_handle_get_instance(h);

    ret = margo_get_input(h, &in);
    assert(ret == HG_SUCCESS);

    const auto rpc_id = remote_procedure::new_id();
    LOGGER_INFO("rpc id: {} name: {} from: {} => "
                "body: {{adhoc_storage_id: {}}}",
                rpc_id, std::quoted(__FUNCTION__), std::quoted(get_address(h)),
                in.server_id);


    auto& adhoc_manager = scord::adhoc_storage_manager::instance();
    admire::error_code ec = adhoc_manager.remove(in.server_id);

    if(!ec) {
        LOGGER_ERROR("rpc id: {} error_msg: \"Error removing job: {}\"", rpc_id,
                     in.server_id);
    }

    out.op_id = rpc_id;
    out.retval = ec;

    LOGGER_INFO("rpc id: {} name: {} to: {} <= "
                "body: {{retval: {}}}",
                rpc_id, std::quoted(__FUNCTION__), std::quoted(get_address(h)),
                ec);

    ret = margo_respond(h, &out);
    assert(ret == HG_SUCCESS);

    ret = margo_free_input(h, &in);
    assert(ret == HG_SUCCESS);

    ret = margo_destroy(h);
    assert(ret == HG_SUCCESS);
}

DEFINE_MARGO_RPC_HANDLER(ADM_remove_adhoc_storage);

static void
ADM_deploy_adhoc_storage(hg_handle_t h) {

+3 −3
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@ void
update_adhoc_storage(const request& req, std::uint64_t adhoc_id,
                     const admire::adhoc_storage::ctx& new_ctx);

void
remove_adhoc_storage(const request& req, std::uint64_t adhoc_id);

void
register_job(const scord::network::request& req,
             const admire::job::resources& job_resources,
@@ -63,9 +66,6 @@ DECLARE_MARGO_RPC_HANDLER(ADM_update_job);
/// ADM_remove_job
DECLARE_MARGO_RPC_HANDLER(ADM_remove_job);

/// ADM_remove_adhoc_storage
DECLARE_MARGO_RPC_HANDLER(ADM_remove_adhoc_storage);

/// ADM_deploy_adhoc_storage
DECLARE_MARGO_RPC_HANDLER(ADM_deploy_adhoc_storage);

+2 −0
Original line number Diff line number Diff line
@@ -186,6 +186,8 @@ main(int argc, char* argv[]) {
                           scord::network::handlers::register_adhoc_storage);
        daemon.set_handler("ADM_update_adhoc_storage"s,
                           scord::network::handlers::update_adhoc_storage);
        daemon.set_handler("ADM_remove_adhoc_storage"s,
                           scord::network::handlers::remove_adhoc_storage);
        daemon.set_handler("ADM_register_job"s,
                           scord::network::handlers::register_job);