Commit 07c1fb0c authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Better separation between library and daemon types

parent 35df04fd
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ liburd_aux_la_SOURCES = \
	backends/remote-backend.hpp \
	common.hpp \
	common/make-unique.hpp \
	common/types.cpp \
	common/types.hpp \
	common/unique-ptr-cast.hpp \
	defaults.hpp \
	io-task.cpp \
+0 −2
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@
#include <thread>
#include <boost/asio.hpp>
#include <boost/filesystem.hpp>
#include <norns.h>
#include <norns-rpc.h>

#include "api/dispatch-table.hpp"

+52 −4
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@
#include <boost/algorithm/string/join.hpp>
#include <boost/range/adaptor/transformed.hpp>

#include "norns.h"
#include "common.hpp"
#include "messages.pb.h"
#include "backends.hpp"
@@ -39,6 +38,41 @@

namespace {

norns::iotask_type decode_iotask_type(::google::protobuf::uint32 type) {

    using norns::iotask_type;

    switch(type) {
        case NORNS_IOTASK_COPY:
            return iotask_type::copy;
        case NORNS_IOTASK_MOVE:
            return iotask_type::move;
        default:
            return iotask_type::unknown;
    }
}

norns::backend_type decode_backend_type(::google::protobuf::uint32 type) {

    using norns::backend_type;

    switch(type) {
        case NORNS_BACKEND_NVML:
            return backend_type::nvml;
        case NORNS_BACKEND_LUSTRE:
            return backend_type::lustre;
        case NORNS_BACKEND_PROCESS_MEMORY:
            return backend_type::process_memory;
        case NORNS_BACKEND_ECHOFS:
            return backend_type::echofs;
        case NORNS_BACKEND_POSIX_FILESYSTEM:
            return backend_type::posix_filesystem;
        default:
            return backend_type::unknown;
    }
}


bool is_valid(const norns::rpc::Request_Task_Resource& res) {
    if(!(res.type() & (NORNS_PROCESS_MEMORY | NORNS_POSIX_PATH))) {
        return false;
@@ -132,7 +166,11 @@ request_ptr request::create_from_buffer(const std::vector<uint8_t>& buffer, int
                if(rpc_req.has_task()) {

                    auto task = rpc_req.task();
                    auto optype = task.optype();
                    iotask_type optype = ::decode_iotask_type(task.optype());

                    if(optype == iotask_type::unknown) {
                        return std::make_unique<bad_request>();
                    }

                    std::shared_ptr<data::resource_info> src_res = ::create_from(task.source());
                    std::shared_ptr<data::resource_info> dst_res = ::create_from(task.destination());
@@ -175,12 +213,17 @@ request_ptr request::create_from_buffer(const std::vector<uint8_t>& buffer, int
                    }

                    std::vector<std::shared_ptr<storage::backend>> backends;
#if 0 
                    //XXX deprecated for now, backends are registered elsewhere
                    //here we should only propagate access rights to backends,
                    // i.e. nsids this job can access and usage quotas
                    backends.reserve(job.backends().size());


                    for(const auto& b : job.backends()) {
                        backends.push_back(storage::backend_factory::create_from(b.type(), b.mount(), b.quota()));
                    }
#endif

                    if(rpc_req.type() == norns::rpc::Request::JOB_REGISTER) {
                        return std::make_unique<job_register_request>(id, hosts, backends);
@@ -225,12 +268,17 @@ request_ptr request::create_from_buffer(const std::vector<uint8_t>& buffer, int
                if(rpc_req.has_backend()) {

                    const auto& b = rpc_req.backend();
                    backend_type type = ::decode_backend_type(b.type());

                    if(type == backend_type::unknown) {
                        break;
                    }

                    if(rpc_req.type() == norns::rpc::Request::BACKEND_REGISTER) {
                        return std::make_unique<backend_register_request>(b.nsid(), b.type(), b.mount(), b.quota());
                        return std::make_unique<backend_register_request>(b.nsid(), type, b.mount(), b.quota());
                    }
                    else { // rpc_req.type() == norns::rpc::Request::BACKEND_UPDATE
                        return std::make_unique<backend_update_request>(b.nsid(), b.type(), b.mount(), b.quota());
                        return std::make_unique<backend_update_request>(b.nsid(), type, b.mount(), b.quota());
                    }
                }
                break;
+5 −6
Original line number Diff line number Diff line
@@ -56,8 +56,7 @@
#include <vector>
#include <string>

#include "norns.h"

#include "common.hpp"

namespace norns {

@@ -169,14 +168,14 @@ using bad_request = detail::request_impl<

using iotask_create_request = detail::request_impl<
    request_type::iotask_create,
    uint32_t, //XXX replace by enum class?
    iotask_type,
    std::shared_ptr<data::resource_info>,
    std::shared_ptr<data::resource_info>
>;

using iotask_status_request = detail::request_impl<
    request_type::iotask_status,
    norns_tid_t
    iotask_id
>;

using ping_request = detail::request_impl<
@@ -221,7 +220,7 @@ using process_unregister_request = detail::request_impl<
using backend_register_request = detail::request_impl<
    request_type::backend_register, 
    std::string, // nsid
    int32_t, // type
    backend_type, // type
    std::string, // mount
    int32_t // quota
>;
@@ -229,7 +228,7 @@ using backend_register_request = detail::request_impl<
using backend_update_request = detail::request_impl<
    request_type::backend_update, 
    std::string, // nsid
    int32_t, // type
    backend_type, // type
    std::string, // mount
    int32_t // quota
>;
+7 −3
Original line number Diff line number Diff line
@@ -81,6 +81,10 @@ norns::rpc::Response_Type encode(norns::api::response_type type) {
    }
}

constexpr ::google::protobuf::uint32 encode(norns::urd_error ecode) {
    return static_cast<::google::protobuf::uint32>(ecode);
}

} // anonymous namespace

namespace norns {
@@ -90,7 +94,7 @@ bool response::store_to_buffer(response_ptr response, std::vector<uint8_t>& buff

    norns::rpc::Response rpc_resp;

    rpc_resp.set_error_code(response->error_code());
    rpc_resp.set_error_code(encode(response->error_code()));
    rpc_resp.set_type(encode(response->type()));
    response->pack_extra_info(rpc_resp);

@@ -119,8 +123,8 @@ void iotask_create_response::pack_extra_info(norns::rpc::Response& r) const {

template<>
std::string iotask_create_response::to_string() const {
    norns_tid_t id = this->get<0>();
    return utils::strerror(m_error_code) + (id != 0 ? " [tid: " + std::to_string(id) + "]": "");
    auto id = this->get<0>();
    return utils::to_string(m_error_code) + (id != 0 ? " [tid: " + std::to_string(id) + "]": "");
}

/////////////////////////////////////////////////////////////////////////////////
Loading