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

Merge branch...

Merge branch 'amiranda/114-missing-information-about-which-job-nodes-can-be-used-for-administrative-purposes' into 'main'

Resolve "Missing information about which job nodes can be used for administrative purposes"

Closes #114

See merge request !85
parents 74d42921 1bd1e360
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ prepare_nodes(size_t n) {
        size_t len = snprintf(NULL, 0, "node-%02zu", i);
        char* id = (char*) alloca(len + 1);
        snprintf(id, len + 1, "node-%02zu", i);
        nodes[i] = ADM_node_create(id);
        nodes[i] = ADM_node_create(id, ADM_NODE_REGULAR);
        if(!nodes[i]) {
            return NULL;
        }
+7 −1
Original line number Diff line number Diff line
@@ -61,6 +61,12 @@ typedef enum {
/** A RPC server */
typedef struct adm_server* ADM_server_t;

/** Node types */
typedef enum {
    ADM_NODE_REGULAR,
    ADM_NODE_ADMINISTRATIVE,
} ADM_node_type_t;

/** A node */
typedef struct adm_node* ADM_node_t;

@@ -247,7 +253,7 @@ ADM_server_destroy(ADM_server_t server);
 * @return A valid ADM_server_t if successful or NULL in case of failure.
 */
ADM_node_t
ADM_node_create(const char* hostname);
ADM_node_create(const char* hostname, ADM_node_type_t type);

/**
 * Destroy a node created by ADM_node_create().
+36 −3
Original line number Diff line number Diff line
@@ -142,8 +142,14 @@ private:

struct node {

    enum class type : std::underlying_type<ADM_node_type_t>::type {
        regular = ADM_NODE_REGULAR,
        administrative = ADM_NODE_ADMINISTRATIVE,
    };

    node();
    explicit node(std::string hostname);
    explicit node(std::string hostname,
                  node::type node_type = node::type::regular);
    explicit node(const ADM_node_t& srv);
    node(const node&) noexcept;
    node(node&&) noexcept;
@@ -156,6 +162,9 @@ struct node {
    std::string
    hostname() const;

    node::type
    get_type() const;

    // The implementation for this must be deferred until
    // after the declaration of the PIMPL class
    template <class Archive>
@@ -637,14 +646,38 @@ struct fmt::formatter<scord::dataset> : formatter<std::string_view> {
    }
};

template <>
struct fmt::formatter<scord::node::type> : fmt::formatter<std::string_view> {
    // parse is inherited from formatter<string_view>.
    template <typename FormatContext>
    auto
    format(const scord::node::type& t, FormatContext& ctx) const {

        using scord::node;
        std::string_view name = "unknown";

        switch(t) {
            case node::type::regular:
                name = "regular";
                break;

            case node::type::administrative:
                name = "administrative";
                break;
        }

        return formatter<std::string_view>::format(name, ctx);
    }
};

template <>
struct fmt::formatter<scord::node> : formatter<std::string_view> {
    // parse is inherited from formatter<string_view>.
    template <typename FormatContext>
    auto
    format(const scord::node& n, FormatContext& ctx) const {
        const auto str =
                fmt::format("{{hostname: {}}}", std::quoted(n.hostname()));
        const auto str = fmt::format("{{hostname: {}, type: {}}}",
                                     std::quoted(n.hostname()), n.get_type());
        return formatter<std::string_view>::format(str, ctx);
    }
};
+2 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ ADM_server_destroy(ADM_server_t server) {
}

ADM_node_t
ADM_node_create(const char* hostname) {
ADM_node_create(const char* hostname, ADM_node_type_t type) {

    struct adm_node* adm_node =
            (struct adm_node*) malloc(sizeof(struct adm_node));
@@ -80,6 +80,7 @@ ADM_node_create(const char* hostname) {
        size_t n = strlen(hostname);
        adm_node->n_hostname = (const char*) calloc(n + 1, sizeof(char));
        strcpy((char*) adm_node->n_hostname, hostname);
        adm_node->n_type = type;
    }

    return adm_node;
+22 −5
Original line number Diff line number Diff line
@@ -96,35 +96,45 @@ class node::impl {

public:
    impl() = default;
    explicit impl(std::string hostname) : m_hostname(std::move(hostname)) {}
    explicit impl(std::string hostname, node::type node_type)
        : m_hostname(std::move(hostname)), m_type(node_type) {}

    std::string
    hostname() const {
        return m_hostname;
    }

    node::type
    get_type() const {
        return m_type;
    }

    template <class Archive>
    void
    load(Archive& ar) {
        ar(SCORD_SERIALIZATION_NVP(m_hostname));
        ar(SCORD_SERIALIZATION_NVP(m_type));
    }

    template <class Archive>
    void
    save(Archive& ar) const {
        ar(SCORD_SERIALIZATION_NVP(m_hostname));
        ar(SCORD_SERIALIZATION_NVP(m_type));
    }

private:
    std::string m_hostname;
    node::type m_type;
};

node::node() = default;

node::node(std::string hostname)
    : m_pimpl(std::make_unique<node::impl>(std::move(hostname))) {}
node::node(std::string hostname, node::type type)
    : m_pimpl(std::make_unique<node::impl>(std::move(hostname), type)) {}

node::node(const ADM_node_t& node) : node::node(node->n_hostname) {}
node::node(const ADM_node_t& node)
    : node::node(node->n_hostname, static_cast<node::type>(node->n_type)) {}

node::node(const node& other) noexcept
    : m_pimpl(std::make_unique<impl>(*other.m_pimpl)) {}
@@ -147,6 +157,11 @@ node::hostname() const {
    return m_pimpl->hostname();
}

node::type
node::get_type() const {
    return m_pimpl->get_type();
}

// since the PIMPL class is fully defined at this point, we can now
// define the serialization function
template <class Archive>
@@ -528,7 +543,9 @@ adhoc_storage::resources::operator ADM_adhoc_resources_t() const {
    std::vector<ADM_node_t> tmp;
    std::transform(m_nodes.cbegin(), m_nodes.cend(), std::back_inserter(tmp),
                   [](const scord::node& n) {
                       return ADM_node_create(n.hostname().c_str());
                       return ADM_node_create(
                               n.hostname().c_str(),
                               static_cast<ADM_node_type_t>(n.get_type()));
                   });

    // N.B. This works because AMD_adhoc_resources_create() internally copies
Loading