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

Plugins now receive a context object

Transfer plugins now receive a new 'context' object that provides access
to relevant data structures from the daemon. This way, they can query
information about the current configuration and status without directly
involving the daemon object.
parent c9857705
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ liburd_aux_la_SOURCES = \
	config/parsers.cpp \
	config/parsers.hpp \
	config/defaults.hpp \
	context.hpp \
	io.hpp \
	io/task.hpp \
	io/task-copy.hpp \

src/context.hpp

0 → 100644
+65 −0
Original line number Diff line number Diff line
/*************************************************************************
 * Copyright (C) 2017-2019 Barcelona Supercomputing Center               *
 *                         Centro Nacional de Supercomputacion           *
 * All rights reserved.                                                  *
 *                                                                       *
 * This file is part of the NORNS Data Scheduler, a service that allows  *
 * other programs to start, track and manage asynchronous transfers of   *
 * data resources transfers requests between different storage backends. *
 *                                                                       *
 * See AUTHORS file in the top level directory for information           *
 * regarding developers and contributors.                                *
 *                                                                       *
 * The NORNS Data Scheduler is free software: you can redistribute it    *
 * and/or modify it under the terms of the GNU Lesser General Public     *
 * License as published by the Free Software Foundation, either          *
 * version 3 of the License, or (at your option) any later version.      *
 *                                                                       *
 * The NORNS Data Scheduler is distributed in the hope that it will be   *
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  *
 * Lesser General Public License for more details.                       *
 *                                                                       *
 * You should have received a copy of the GNU Lesser General             *
 * Public License along with the NORNS Data Scheduler.  If not, see      *
 * <http://www.gnu.org/licenses/>.                                       *
 *************************************************************************/

#ifndef NORNS_CONTEXT_HPP
#define NORNS_CONTEXT_HPP

#include <boost/filesystem.hpp>
#include <memory>

namespace bfs = boost::filesystem;

namespace hermes {
    class async_engine;
} // namespace hermes

namespace norns {

struct context {

    context(bfs::path staging_directory,
            std::shared_ptr<hermes::async_engine> network_service) :
        m_staging_directory(std::move(staging_directory)),
        m_network_service(std::move(network_service)) { }

    bfs::path 
    staging_directory() const {
        return m_staging_directory;
    }

    std::shared_ptr<hermes::async_engine>
    network_service() const {
        return m_network_service;
    }

    bfs::path m_staging_directory;
    std::shared_ptr<hermes::async_engine> m_network_service;
};

} // namespace norns

#endif // NORNS_CONTEXT_HPP
+4 −0
Original line number Diff line number Diff line
@@ -199,6 +199,10 @@ copy_directory(const std::shared_ptr<norns::io::task_info>& task_info,
namespace norns {
namespace io {

local_path_to_local_path_transferor::local_path_to_local_path_transferor(
    const context& ctx) :
        m_ctx(ctx) {}

bool 
local_path_to_local_path_transferor::validate(
        const std::shared_ptr<data::resource_info>& src_info,
+10 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@

#include <memory>
#include <system_error>
#include "context.hpp"
#include "transferor.hpp"

namespace norns {
@@ -48,8 +49,12 @@ namespace io {

struct local_path_to_local_path_transferor : public transferor {

    bool validate(const std::shared_ptr<data::resource_info>& src_info,
                  const std::shared_ptr<data::resource_info>& dst_info) const override final;
    local_path_to_local_path_transferor(const context& ctx);

    bool 
    validate(const std::shared_ptr<data::resource_info> &src_info,
             const std::shared_ptr<data::resource_info> &dst_info)
        const override final;

    std::error_code 
    transfer(const auth::credentials& auth,                
@@ -67,6 +72,9 @@ struct local_path_to_local_path_transferor : public transferor {

    std::string 
    to_string() const override final;

private:
    context m_ctx;
};


+6 −5
Original line number Diff line number Diff line
@@ -127,9 +127,10 @@ unpack_archive(const bfs::path& archive_path,
namespace norns {
namespace io {

local_path_to_remote_resource_transferor::local_path_to_remote_resource_transferor(
        std::shared_ptr<hermes::async_engine> network_service) :
    m_network_service(network_service) { }
local_path_to_remote_resource_transferor::
    local_path_to_remote_resource_transferor(const context& ctx) :
        m_staging_directory(ctx.staging_directory()),
        m_network_service(ctx.network_service()) { }

bool 
local_path_to_remote_resource_transferor::validate(
@@ -172,7 +173,7 @@ local_path_to_remote_resource_transferor::transfer(

            const bfs::path ar_path =
                ::pack_archive("norns-archive-%%%%-%%%%-%%%%.tar",
                               "/tmp",
                               m_staging_directory,
                               {{true, d_src.canonical_path(), d_dst.name()}},
                               ec);

@@ -320,7 +321,7 @@ local_path_to_remote_resource_transferor::accept_transfer(
                d_dst.name()},
            /* parent_path */
            bfs::path{is_collection ?
                "/tmp" :
                m_staging_directory :
                d_dst.parent()->mount()},
            remote_buffers.size(),
            ec);
Loading