Skip to content

Commit

Permalink
Merge pull request #23 from FAIRDataPipeline/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
RyanJField authored Apr 24, 2022
2 parents fa62b6c + 9175149 commit 1bcc48a
Show file tree
Hide file tree
Showing 35 changed files with 886 additions and 322 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ INCLUDE( external/jsoncpp.cmake )
INCLUDE( external/digestpp.cmake )
INCLUDE( external/curl.cmake )
INCLUDE( external/yaml_cpp.cmake )
INCLUDE( external/spdlog.cmake )
INCLUDE( external/toml11.cmake )
INCLUDE( external/ghc.cmake )

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ $ cmake --build build --config=Release
## Outline
The main class the user will interact with is `DataPipeline` which has only the required methods such as `link_read` etc. This class has a member which is a pointer to an underlying `DataPipelineImpl_` class which performs the various procedures required to handle the data. A logger has been used to give as much feedback to the user as possible, the verbosity being handled by a log level argument.

### Logging
The environment variable `FDP_LOG_LEVEL=[TRACE:DEBUG:INFO:WARN:ERROR:CRITICAL:OFF]` can be set to specify the logging output level.

## Unit Tests
The unit tests use the local registry, this needs to be running prior to running the tests see: [the CLI documentation](https://github.com/FAIRDataPipeline/FAIR-CLI#registry)
Expand Down
1 change: 1 addition & 0 deletions external/digestpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SET( DIGESTCPP_COMMIT "34ff2eeae397ed744d972d86b5a20f603b029fbd" )
# So tell the compiler to exclude min and max macros in windows
IF(WIN32)
add_definitions(-DNOMINMAX)
add_definitions(-DNOGDI)
ENDIF()

MESSAGE( STATUS "[DigestCPP]" )
Expand Down
2 changes: 2 additions & 0 deletions external/jsoncpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ MESSAGE( STATUS "[JsonCPP]" )
MESSAGE( STATUS "\tJsonCpp Will be installed." )
MESSAGE( STATUS "\tURL: ${JSONCPP_URL}" )

SET (JSONCPP_WITH_TESTS OFF CACHE INTERNAL "Don't Build cpp tests")

include(FetchContent)
FetchContent_Declare(
JsonCpp
Expand Down
13 changes: 0 additions & 13 deletions external/spdlog.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions include/fdp/exceptions.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdexcept>
#include <string>

namespace FDP {
namespace FairDataPipeline {
class config_parsing_error : public std::runtime_error {
public:
config_parsing_error(const std::string& message)
Expand Down Expand Up @@ -37,6 +37,6 @@ public:
write_error(const std::string& message) : std::runtime_error(message) {}
};

}; // namespace FDP
}; // namespace FairDataPipeline

#endif
34 changes: 20 additions & 14 deletions include/fdp/fdp.hxx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef __FDP__
#define __FDP__

#include "spdlog/spdlog.h"
#include <ghc/filesystem.hpp>
#include "utilities/logging.hxx"

//#include "fdp/registry/datapipeline.hxx"
#include <ghc/filesystem.hpp>

namespace FDP {
namespace FairDataPipeline {
/**
* @brief DataPipeline Class:
* A PIMPL Class for interacting the the FAIR Data Pipeline
Expand All @@ -15,31 +14,29 @@ namespace FDP {
class DataPipeline {

public:
typedef std::shared_ptr< DataPipeline > sptr;
/**
* @brief Construct a new Data Pipeline (PIMPL)
*
* @param config_file_path
* @param script_file_path
* @param token
* @param log_level
*/
explicit DataPipeline(
static sptr construct(
const std::string &config_file_path,
const std::string &script_file_path,
std::string token = "",
spdlog::level::level_enum log_level = spdlog::level::info);
std::string token = "" );


/**
* @brief Destroy the Data Pipeline object
*
*/
~DataPipeline();

DataPipeline(DataPipeline &&rhs) noexcept;
DataPipeline &operator=(DataPipeline &&rhs) noexcept;
//DataPipeline(DataPipeline &&rhs) noexcept;
//DataPipeline &operator=(DataPipeline &&rhs) noexcept;

DataPipeline(const DataPipeline &rhs);
DataPipeline &operator=(const DataPipeline &rhs);

/**
* @brief Return a path to a given data product
Expand Down Expand Up @@ -68,10 +65,19 @@ namespace FDP {
void finalise();

private:
explicit DataPipeline(
const std::string &config_file_path,
const std::string &script_file_path,
std::string token = ""
);

DataPipeline(const DataPipeline &rhs) = delete;

DataPipeline &operator=(const DataPipeline &rhs) = delete;

class impl;

std::shared_ptr< DataPipeline::impl > pimpl_;
};
}; // namespace FDP

}; // namespace FairDataPipeline
#endif
6 changes: 3 additions & 3 deletions include/fdp/objects/api_object.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "fdp/utilities/logging.hxx"

namespace FDP {
namespace FairDataPipeline {
/**
* @brief Class for API objects
*
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace FDP {
* @return int object id e.g. if the uri is http://127.0.0.1/object/1
* the object id will be 1
*/
int get_id();
int get_id() const ;
/**
* @brief Get the object type from the uri
*
Expand All @@ -58,7 +58,7 @@ namespace FDP {
*/
static int get_id_from_string(std::string url);

std::string get_type();
std::string get_type() const ;
/**
* @brief Get the object uri
*
Expand Down
20 changes: 12 additions & 8 deletions include/fdp/objects/config.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
#include "fdp/objects/api_object.hxx"
#include "fdp/objects/io_object.hxx"

namespace FDP {
namespace FairDataPipeline {
/**
* @brief class for interacting with confifurations
*
*/
class Config {
public:
typedef std::shared_ptr< Config > sptr;

typedef std::map< std::string, IOObject > map_type;

private:
const ghc::filesystem::path config_file_path_;
const ghc::filesystem::path config_dir_;
Expand Down Expand Up @@ -59,11 +64,11 @@ namespace FDP {

ApiObject::sptr code_run_;

std::map<std::string, IOObject> writes_;
std::map<std::string, IOObject> reads_;
map_type writes_;
map_type reads_;

std::map<std::string, IOObject> outputs_;
std::map<std::string, IOObject> inputs_;
map_type outputs_;
map_type inputs_;

RESTAPI rest_api_location_ = RESTAPI::LOCAL;

Expand All @@ -87,7 +92,6 @@ namespace FDP {


public:
typedef std::shared_ptr< Config > sptr;

static Config::sptr construct(const ghc::filesystem::path &config_file_path,
const ghc::filesystem::path &script_file_path,
Expand Down Expand Up @@ -225,15 +229,15 @@ namespace FDP {
* @param data_product
* @return ghc::filesystem::path
*/
ghc::filesystem::path link_write(std::string &data_product);
ghc::filesystem::path link_write( const std::string &data_product);

/**
* @brief Return the filepath to a given data product
*
* @param data_product
* @return ghc::filesystem::path
*/
ghc::filesystem::path link_read(std::string &data_product);
ghc::filesystem::path link_read(const std::string& data_product);

/**
* @brief Finalise the pipeline
Expand Down
6 changes: 3 additions & 3 deletions include/fdp/objects/io_object.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "fdp/utilities/logging.hxx"
#include "fdp/objects/api_object.hxx"

namespace FDP {
namespace FairDataPipeline {
/**
* @brief Class for API objects
*
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace FDP {
*
* @return const std::string&
*/
const std::string& get_use_namespace() {return use_namespace_;}
const std::string& get_use_namespace() const {return use_namespace_;}

/**
* @brief Get the path of the data product
Expand All @@ -144,7 +144,7 @@ namespace FDP {
*
* @return std::string
*/
const std::string& get_component_description() {return component_description_;}
const std::string& get_component_description() const {return component_description_;}

/**
* @brief Check whether the data product is public
Expand Down
6 changes: 3 additions & 3 deletions include/fdp/objects/metadata.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! **************************************************************************
* @file fdp/objects/metadata.hxx
* @file FairDataPipeline/objects/metadata.hxx
* @author K. Zarebski (UKAEA)
* @date 2021-05-05
* @brief File containing methods for handling of metadata
Expand Down Expand Up @@ -29,7 +29,7 @@
#include <unistd.h>
#endif

namespace FDP {
namespace FairDataPipeline {
/*! **************************************************************************
* @brief calculates a hash from a given input file via SHA1
*
Expand Down Expand Up @@ -94,6 +94,6 @@ bool file_exists( const std::string &Filename );
*/
std::string read_token(const ghc::filesystem::path &token_path);

}; // namespace FDP
}; // namespace FairDataPipeline

#endif
19 changes: 12 additions & 7 deletions include/fdp/registry/api.hxx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*! **************************************************************************
* @file fdp/registry/api.hxx
* @file FairDataPipeline/registry/api.hxx
* @author K. Zarebski (UKAEA)
* @date 2021-05-05
* @brief File containing classes and methods for connecting to the RestAPI
*
* The classes and methods within this file are used to access the FDP
* The classes and methods within this file are used to access the FairDataPipeline
* Data Pipeline RestAPI, they handle sending of requests and retrieval of
* data as JSON strings
****************************************************************************/
Expand All @@ -27,7 +27,7 @@
#include "fdp/utilities/json.hxx"
#include "fdp/utilities/logging.hxx"

namespace FDP {
namespace FairDataPipeline {
/*! **************************************************************************
* @enum RESTAPI
* @brief selection of either local or remote pipeline running
Expand All @@ -39,6 +39,7 @@ enum class RESTAPI {
LOCAL /*!< Run from local registry */
};

#if 0
/*! **************************************************************************
* @brief function for writing to file from a CURL call
* @author K. Zarebski (UKAEA)
Expand All @@ -50,6 +51,7 @@ enum class RESTAPI {
* @return size_t
****************************************************************************/
size_t write_func_(void *ptr, size_t size, size_t nmemb, std::string *data);
#endif

/*! **************************************************************************
* @class API
Expand All @@ -70,8 +72,8 @@ public:
*
* @param url_root the root of the query address, e.g. localhost:8000/api
***************************************************************************/
API(std::string url_root)
: url_root_(API::append_with_forward_slash(url_root)) {}
static sptr construct( const std::string& url_root );


/**
* @brief sends the given 'packet' of information to the RestAPI
Expand Down Expand Up @@ -164,6 +166,9 @@ public:
static std::string remove_leading_forward_slash(std::string str);

private:
API( const std::string& url_root)
: url_root_(API::append_with_forward_slash(url_root)) {}

std::string url_root_;
CURL *setup_json_session_(std::string &addr_path, std::string *response,
long &http_code, std::string token = "");
Expand All @@ -181,8 +186,8 @@ private:
ghc::filesystem::path out_path);
};

std::string url_encode(std::string url);
std::string url_encode(const std::string& url);

}; // namespace FDP
}; // namespace FairDataPipeline

#endif
14 changes: 8 additions & 6 deletions include/fdp/registry/data_io.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! **************************************************************************
* @file fdp/registry/config.hxx
* @file FairDataPipeline/registry/config.hxx
* @author K. Zarebski (UKAEA)
* @date 2021-05-06
* @brief File containing classes for interacting with the local file system
Expand Down Expand Up @@ -27,7 +27,7 @@
#include "fdp/utilities/logging.hxx"
#include "fdp/utilities/semver.hxx"

namespace FDP {
namespace FairDataPipeline {

/*! ***************************************************************************
* @brief read the value of a point estimate from a given TOML file
Expand Down Expand Up @@ -87,8 +87,10 @@ ghc::filesystem::path create_estimate(T &value,

toml_out_.close();

APILogger->debug("FileSystem:CreateEstimate: Wrote point estimate to '{0}'",
output_filename_.string());

auto the_logger = logger::get_logger();
the_logger->debug()
<< "FileSystem:CreateEstimate: Wrote point estimate to '" << output_filename_.string() << "'";

return output_filename_;
}
Expand All @@ -101,6 +103,6 @@ ghc::filesystem::path create_estimate(T &value,
*/
std::string get_first_key_(const toml::value data_table);

}; // namespace FDP
}; // namespace FairDataPipeline

#endif
#endif
Loading

0 comments on commit 1bcc48a

Please sign in to comment.