<commit_before>/**
 * @file clusterProxyHelper.cc
 * @author <NAME>
 * @copyright (C) 2013 ACK CYFRONET AGH
 * @copyright This software is released under the MIT license cited in 'LICENSE.txt'
 */

#include "clusterProxyHelper.h"

#include "communication/communicator.h"
#include "communication/exception.h"
#include "logging.h"
#include "make_unique.h"
#include "remote_file_management.pb.h"

#include <boost/algorithm/string/case_conv.hpp>
#include <boost/any.hpp>

#include <functional>

using namespace std;
using namespace std::placeholders;
using namespace veil::protocol::remote_file_management;
using namespace veil::protocol::communication_protocol;

namespace veil {
namespace helpers {

std::unique_ptr<RemoteFileMangement> wrap(const google::protobuf::Message &msg)
{
    auto wrapper = std::make_unique<RemoteFileMangement>();
    wrapper->set_message_type(boost::algorithm::to_lower_copy(msg.GetDescriptor()->name()));
    msg.SerializeToString(wrapper->mutable_input());
    wrapper->set_space_id(m_spaceId);
    return std::move(wrapper);
}

template<typename AnswerType>
string ClusterProxyHelper::requestMessage(const google::protobuf::Message &msg,
                                          const std::chrono::milliseconds timeout)
{
    try
    {
        const auto answer = m_communicator->communicate<AnswerType>(
                    communication::ServerModule::REMOTE_FILES_MANAGER, *wrap(msg), 2, timeout);
        return answer->worker_answer();
    }
    catch(communication::Exception &e)
{
        LOG(WARNING) << "Communication error: " << e.what();
    }

    return {};
}

template<typename AnswerType>
string ClusterProxyHelper::requestMessage(const google::protobuf::Message &msg)
{
    try
    {
        const auto answer = m_communicator->communicate<AnswerType>(
                    communication::ServerModule::REMOTE_FILES_MANAGER, *wrap(msg), 2);
        return answer->worker_answer();
}
    catch(communication::Exception &e)
{
        LOG(WARNING) << "Communication error: " << e.what();
    }

    return {};
}

string ClusterProxyHelper::requestAtom(const google::protobuf::Message &msg)
{
    try
{
        const auto answer = m_communicator->communicate<Atom>(
                    communication::ServerModule::REMOTE_FILES_MANAGER, *wrap(msg), 2);

    Atom atom;
        if(answer->has_worker_answer())
        {
            atom.ParseFromString(answer->worker_answer());
        return atom.value();
    }
}
    catch(communication::Exception &e)
{
        LOG(WARNING) << "Communication error: " << e.what();
    }

    return {};
}<commit_msg>VFS-749: fix whitespaces<commit_after>/**
 * @file clusterProxyHelper.cc
 * @author <NAME>
 * @copyright (C) 2013 ACK CYFRONET AGH
 * @copyright This software is released under the MIT license cited in 'LICENSE.txt'
 */

#include "clusterProxyHelper.h"

#include "communication/communicator.h"
#include "communication/exception.h"
#include "logging.h"
#include "make_unique.h"
#include "remote_file_management.pb.h"

#include <boost/algorithm/string/case_conv.hpp>
#include <boost/any.hpp>

#include <functional>

using namespace std;
using namespace std::placeholders;
using namespace veil::protocol::remote_file_management;
using namespace veil::protocol::communication_protocol;

namespace veil {
namespace helpers {

std::unique_ptr<RemoteFileMangement> wrap(const google::protobuf::Message &msg)
{
    auto wrapper = std::make_unique<RemoteFileMangement>();
    wrapper->set_message_type(boost::algorithm::to_lower_copy(msg.GetDescriptor()->name()));
    msg.SerializeToString(wrapper->mutable_input());
    wrapper->set_space_id(m_spaceId);
    return std::move(wrapper);
}

template<typename AnswerType>
string ClusterProxyHelper::requestMessage(const google::protobuf::Message &msg,
                                          const std::chrono::milliseconds timeout)
{
    try
    {
        const auto answer = m_communicator->communicate<AnswerType>(
                    communication::ServerModule::REMOTE_FILES_MANAGER, *wrap(msg), 2, timeout);
        return answer->worker_answer();
    }
    catch(communication::Exception &e)
    {
        LOG(WARNING) << "Communication error: " << e.what();
    }

    return {};
}

template<typename AnswerType>
string ClusterProxyHelper::requestMessage(const google::protobuf::Message &msg)
{
    try
    {
        const auto answer = m_communicator->communicate<AnswerType>(
                    communication::ServerModule::REMOTE_FILES_MANAGER, *wrap(msg), 2);
        return answer->worker_answer();
    }
    catch(communication::Exception &e)
    {
        LOG(WARNING) << "Communication error: " << e.what();
    }

    return {};
}

string ClusterProxyHelper::requestAtom(const google::protobuf::Message &msg)
{
    try
    {
        const auto answer = m_communicator->communicate<Atom>(
                    communication::ServerModule::REMOTE_FILES_MANAGER, *wrap(msg), 2);

        Atom atom;
        if(answer->has_worker_answer())
        {
            atom.ParseFromString(answer->worker_answer());
            return atom.value();
        }
    }
    catch(communication::Exception &e)
    {
        LOG(WARNING) << "Communication error: " << e.what();
    }

    return {};
}
{'fraction_non_alphanumeric': 0.12989493791786055, 'fraction_numerical': 0.0032473734479465137, 'mean_word_length': 3.7256317689530687, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686982', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1483, 'n_words': 290}